fix(anthropic): resolve mypy lint errors in pass-through handler and adapter

This commit is contained in:
Gennaro Malafronte 2026-04-27 19:18:53 +02:00
parent 9ec472bb97
commit 4aa6f02beb
2 changed files with 7 additions and 5 deletions

View file

@ -1331,7 +1331,7 @@ class LiteLLMAnthropicMessagesAdapter:
openai_finish_reason=response.choices[0].finish_reason # type: ignore
)
# extract usage
usage: Usage = response.usage
usage: Usage = response.usage # type: ignore[attr-defined]
uncached_input_tokens = usage.prompt_tokens or 0
cached_tokens = 0
if hasattr(usage, "prompt_tokens_details") and usage.prompt_tokens_details:

View file

@ -48,8 +48,10 @@ def _should_route_to_responses_api(custom_llm_provider: Optional[str]) -> bool:
def _sanitize_think_tag_text_blocks(
response: Union[AnthropicMessagesResponse, AsyncIterator]
) -> Union[AnthropicMessagesResponse, AsyncIterator]:
response: Union[
AnthropicMessagesResponse, AsyncIterator[Any], Coroutine[Any, Any, Any]
],
) -> Union[AnthropicMessagesResponse, AsyncIterator[Any], Coroutine[Any, Any, Any]]:
if not isinstance(response, dict):
return response
@ -57,7 +59,7 @@ def _sanitize_think_tag_text_blocks(
if not isinstance(content, list):
return response
sanitized_content: List[Dict[str, Any]] = []
sanitized_content: List[Any] = []
for block in content:
if not isinstance(block, dict):
sanitized_content.append(block)
@ -221,7 +223,7 @@ async def anthropic_messages(
client: Optional[AsyncHTTPHandler] = None,
custom_llm_provider: Optional[str] = None,
**kwargs,
) -> Union[AnthropicMessagesResponse, AsyncIterator]:
) -> Union[AnthropicMessagesResponse, AsyncIterator[Any], Coroutine[Any, Any, Any]]:
"""
Async: Make llm api request in Anthropic /messages API spec
"""