The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: add missing return type annotations to iterator protocol methods in streaming_handler (#21750)
Monesh Ram083c8998e616
diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.pyindex 1f739a60b40..6b83ded9d25 100644--- a/litellm/litellm_core_utils/streaming_handler.py+++ b/litellm/litellm_core_utils/streaming_handler.py@@ -6,7 +6,7 @@ import loggingimport threadingimport timeimport traceback-from typing import Any, Callable, Dict, List, Optional, Union, cast+from typing import Any, AsyncIterator, Callable, Dict, Iterator, List, Optional, Union, castimport anyioimport httpx@@ -151,10 +151,10 @@ class CustomStreamWrapper:self.is_function_call = self.check_is_function_call(logging_obj=logging_obj)self.created: Optional[int] = None- def __iter__(self):+ def __iter__(self) -> Iterator["ModelResponseStream"]:return self- def __aiter__(self):+ def __aiter__(self) -> AsyncIterator["ModelResponseStream"]:return selfasync def aclose(self):@@ -1726,7 +1726,7 @@ class CustomStreamWrapper:model_response.choices[0].finish_reason = "tool_calls"return model_response- def __next__(self): # noqa: PLR0915+ def __next__(self) -> "ModelResponseStream": # noqa: PLR0915cache_hit = Falseif (self.custom_llm_provider is not None@@ -1900,7 +1900,7 @@ class CustomStreamWrapper:return self.completion_stream- async def __anext__(self): # noqa: PLR0915+ async def __anext__(self) -> "ModelResponseStream": # noqa: PLR0915cache_hit = Falseif (self.custom_llm_provider is not Nonediff --git a/ruff.toml b/ruff.tomlindex a3104466710..43ff802a684 100644--- a/ruff.toml+++ b/ruff.toml@@ -12,4 +12,7 @@ exclude = ["litellm/types/*", "litellm/__init__.py", "litellm/proxy/example_conf"litellm/llms/anthropic/chat/__init__.py" = ["F401"]"litellm/llms/azure_ai/embed/__init__.py" = ["F401"]"litellm/llms/azure_ai/rerank/__init__.py" = ["F401"]-"litellm/llms/bedrock/chat/__init__.py" = ["F401"]\ No newline at end of file+"litellm/llms/bedrock/chat/__init__.py" = ["F401"]+"litellm/proxy/utils.py" = ["F401", "PLR0915"]+"litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py" = ["PLR0915"]+"litellm/proxy/guardrails/guardrail_hooks/guardrail_benchmarks/test_eval.py" = ["PLR0915"]