From 54c74050839fb5042e3799a4407c90b469014e0e Mon Sep 17 00:00:00 2001 From: Daniel Cherubini Date: Mon, 14 Sep 2026 19:00:20 +0200 Subject: [PATCH] fix: clear type-discipline gate breaches (LIT001 +3, LIT009 +3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LIT009: the PR's three # type: ignore on chunk.choices / response.choices were dead (enableTypeIgnoreComments is false), and LIT009 is frozen at limit 0. Removed them and widened the three receiving signatures to Sequence[... | Choices] so the list/Choices/StreamingChoices call sites assign cleanly by covariance. LIT001: the +3 came from the new code's mutable-collection annotations (classifier choices list, new accumulator helper choices list, and the _is_thinking_disabled dict param) — switched to Sequence / Mapping read-only views. --- .../experimental_pass_through/adapters/handler.py | 2 +- .../adapters/streaming_iterator.py | 4 ++-- .../adapters/transformation.py | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py index 87bb3c4ed25..06446de1ff1 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py @@ -319,7 +319,7 @@ ANTHROPIC_ADAPTER: Final = AnthropicAdapter() class LiteLLMMessagesToCompletionTransformationHandler: @staticmethod - def _is_thinking_disabled(thinking: dict | None) -> bool: + def _is_thinking_disabled(thinking: Mapping | None) -> bool: """Return True when the client's thinking param is absent or explicitly disabled.""" return thinking is None or (isinstance(thinking, dict) and thinking.get("type") == "disabled") diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py index 2efa9157575..0c77fd495e8 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py @@ -1169,7 +1169,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): return ( LiteLLMAnthropicMessagesAdapter._classify_streaming_chunk( - choices=chunk.choices, # type: ignore + choices=chunk.choices, thinking_disabled=thinking_disabled, ) != "skip" @@ -1232,7 +1232,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): block_type, content_block_start, ) = LiteLLMAnthropicMessagesAdapter()._translate_streaming_openai_chunk_to_anthropic_content_block( - choices=chunk.choices, # type: ignore + choices=chunk.choices, thinking_disabled=self.thinking_disabled, ) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py index 546ae55ec29..2bc925c6c83 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py @@ -1562,7 +1562,7 @@ class LiteLLMAnthropicMessagesAdapter: @staticmethod def _classify_streaming_chunk( - choices: list["OpenAIStreamingChoice | StreamingChoices"], + choices: Sequence["OpenAIStreamingChoice | StreamingChoices"], thinking_disabled: bool = False, ) -> Literal["thinking", "redacted_thinking", "tool_use", "text", "skip"]: """ @@ -1667,7 +1667,7 @@ class LiteLLMAnthropicMessagesAdapter: def _translate_streaming_openai_chunk_to_anthropic_content_block( self, - choices: list[OpenAIStreamingChoice | StreamingChoices], + choices: Sequence["OpenAIStreamingChoice | StreamingChoices | Choices"], thinking_disabled: bool = False, ) -> tuple[ Literal["text", "tool_use", "thinking", "redacted_thinking"], @@ -1732,7 +1732,7 @@ class LiteLLMAnthropicMessagesAdapter: def _translate_streaming_openai_chunk_to_anthropic( self, - choices: list[OpenAIStreamingChoice | StreamingChoices], + choices: Sequence["OpenAIStreamingChoice | StreamingChoices | Choices"], thinking_disabled: bool = False, ) -> tuple[ StreamingContentBlockDeltaType, @@ -1757,7 +1757,7 @@ class LiteLLMAnthropicMessagesAdapter: def _accumulate_streaming_chunk_payloads( self, - choices: list[OpenAIStreamingChoice | StreamingChoices], + choices: Sequence["OpenAIStreamingChoice | StreamingChoices"], thinking_disabled: bool = False, ) -> tuple[str, str, str, str | None]: """Fold a chunk's choices into (text, reasoning_content, reasoning_signature, partial_json). @@ -1838,7 +1838,7 @@ class LiteLLMAnthropicMessagesAdapter: type_of_content, content_block_delta, ) = self._translate_streaming_openai_chunk_to_anthropic( - choices=response.choices, # type: ignore + choices=response.choices, thinking_disabled=thinking_disabled, ) return ContentBlockDelta(