fix(clinepass): type logging_obj and encoding instead of Any

The `lint` job's failing step was not plain ruff but
`scripts/ruff_strict_gate.py`, a strict-rule budget gate that compares totals
against the base commit: "ANN401: total 361 over limit 119 (this change added
2)", pointing at transformation.py:192 and :197.

Those two were `logging_obj: Any` and `encoding: Any`. The base class already
types them (`litellm/llms/base_llm/chat/transformation.py:350,355`), so they now
use `LiteLLMLoggingObj` and `"Tokenizer | None"`, imported under TYPE_CHECKING
with an `Any` fallback exactly as litellm/llms/openai/chat/gpt_transformation.py
does -- importing litellm_logging at runtime from a provider module risks a
circular import, which is presumably why that pattern exists.

This was also codex review finding #6, which said to "use the existing
logging/tokenizer types as current CometAPI and Perplexity transformations do".
I had read that as satisfied by the builtin-generics work and it was not.

`scripts/ruff_strict_gate.py --base upstream/main` now reports "OK: every strict
rule is within its codebase ceiling"; ruff clean under both CI configurations;
43 tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Daniel JB Clark 2026-10-03 12:48:53 -04:00
parent d33e84b6e0
commit cb9aeab01d
No known key found for this signature in database

View file

@ -15,7 +15,7 @@ Documentation: https://docs.cline.bot/
"""
import json
from typing import Any, Final
from typing import TYPE_CHECKING, Any, Final
import httpx
@ -27,6 +27,17 @@ from litellm.types.utils import ModelResponse
from ...openai.chat.gpt_transformation import OpenAIGPTConfig
from ..common_utils import ClinePassException
# Mirrors litellm/llms/openai/chat/gpt_transformation.py: these are needed only
# for annotations, and importing litellm_logging at runtime from a provider
# module risks a circular import.
if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj
from litellm.litellm_core_utils.tokenizer import Encoding as Tokenizer
LiteLLMLoggingObj = _LiteLLMLoggingObj
else:
LiteLLMLoggingObj = Any
CLINEPASS_API_BASE: Final = "https://api.cline.bot/api/v1"
# ClinePass nests the completion under this key on non-streaming responses.
@ -189,12 +200,12 @@ class ClinePassConfig(OpenAIGPTConfig):
model: str,
raw_response: httpx.Response,
model_response: ModelResponse,
logging_obj: Any,
logging_obj: LiteLLMLoggingObj,
request_data: dict,
messages: list[AllMessageValues],
optional_params: dict,
litellm_params: dict,
encoding: Any,
encoding: "Tokenizer | None",
api_key: str | None = None,
json_mode: bool | None = None,
) -> ModelResponse: