From 152b1e15d2c05737341b5c5ceccf6522508d9932 Mon Sep 17 00:00:00 2001 From: Emerson Gomes Date: Sat, 26 Sep 2026 09:03:44 -0500 Subject: [PATCH] refactor(realtime): align annotations with current lint rules --- litellm/litellm_core_utils/realtime_streaming.py | 3 +-- litellm/llms/custom_httpx/llm_http_handler.py | 2 +- .../llms/openai/transcriptions/gpt_transformation.py | 4 +--- litellm/llms/openai/transcriptions/handler.py | 4 +++- litellm/proxy/realtime_endpoints/endpoints.py | 10 +++------- litellm/realtime_api/main.py | 10 ++++++---- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/litellm/litellm_core_utils/realtime_streaming.py b/litellm/litellm_core_utils/realtime_streaming.py index a8284a20ad7..455967f7cfe 100644 --- a/litellm/litellm_core_utils/realtime_streaming.py +++ b/litellm/litellm_core_utils/realtime_streaming.py @@ -524,9 +524,8 @@ class RealTimeStreaming: for event in self.messages: if event.get("type") != "session.closed": continue - event_usage = event.get("usage") # rebind-ok: each close event carries independent usage if ( - isinstance(event_usage, dict) + isinstance(event_usage := event.get("usage"), dict) and normalized_audio_duration_seconds(event_usage.get("output_seconds")) is not None ): self._translation_usage_finalized = True diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index 136926f2912..928ba17d305 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -6162,7 +6162,7 @@ class BaseLLMHTTPHandler: configured_client: Final = openai_client.with_options( timeout=timeout, set_default_headers={ # mutable-ok: OpenAI SDK accepts a mutable custom-header mapping - key: str(value) # mutable-ok: SDK headers are materialized as a concrete string mapping + key: str(value) for key, value in (extra_headers or {}).items() # mutable-ok: SDK requires concrete headers }, ) diff --git a/litellm/llms/openai/transcriptions/gpt_transformation.py b/litellm/llms/openai/transcriptions/gpt_transformation.py index 81f3abd217a..c55ecf1e56c 100644 --- a/litellm/llms/openai/transcriptions/gpt_transformation.py +++ b/litellm/llms/openai/transcriptions/gpt_transformation.py @@ -40,9 +40,7 @@ class OpenAIGPTAudioTranscriptionConfig(OpenAIWhisperAudioTranscriptionConfig): class OpenAIGPTTranscribeAudioTranscriptionConfig(OpenAIGPTAudioTranscriptionConfig): - def get_supported_openai_params( # mutable-ok: base transcription interface returns a mutable parameter list - self, model: str - ) -> list[OpenAIAudioTranscriptionOptionalParams]: + def get_supported_openai_params(self, model: str) -> list[OpenAIAudioTranscriptionOptionalParams]: return [ "prompt", "response_format", diff --git a/litellm/llms/openai/transcriptions/handler.py b/litellm/llms/openai/transcriptions/handler.py index de020f4cae3..ac57cc72290 100644 --- a/litellm/llms/openai/transcriptions/handler.py +++ b/litellm/llms/openai/transcriptions/handler.py @@ -57,7 +57,9 @@ class OpenAIAudioTranscription(OpenAIChatCompletion): if data.get("stream") is True: stream_response: Final = openai_client.audio.transcriptions.create(**sdk_data, timeout=timeout) return None, stream_response - raw_response: Final = openai_client.audio.transcriptions.with_raw_response.create(**sdk_data, timeout=timeout) + raw_response: Final = openai_client.audio.transcriptions.with_raw_response.create( + **sdk_data, timeout=timeout + ) headers: Final = dict(raw_response.headers) response: Final = raw_response.parse() return headers, response diff --git a/litellm/proxy/realtime_endpoints/endpoints.py b/litellm/proxy/realtime_endpoints/endpoints.py index eb3a8430923..f358111835b 100644 --- a/litellm/proxy/realtime_endpoints/endpoints.py +++ b/litellm/proxy/realtime_endpoints/endpoints.py @@ -139,7 +139,7 @@ async def _authorize_and_bind_nested_transcription_models( session_data: dict, # mutable-ok: session payload is rewritten in place for provider serialization user_api_key_dict: UserAPIKeyAuth, llm_model_list: list | None, # mutable-ok: inherited auth helper accepts the proxy model list - llm_router: Any, + llm_router: "Router | None", ) -> None: nested_models: Final = tuple(_transcription_model_candidates_from_session(session_data)) for nested_model in nested_models: @@ -515,18 +515,14 @@ async def proxy_realtime_calls( session_type = _coerce_realtime_session_type(raw_session_type) if is_translation_request != (raw_session_type == "translation"): return Response( - content=json.dumps( # mutable-ok: JSON encoder requires the endpoint error payload mapping - {"error": "Token is not valid for this Realtime endpoint"} - ), + content=json.dumps({"error": "Token is not valid for this Realtime endpoint"}), status_code=http_status.HTTP_401_UNAUTHORIZED, media_type="application/json", ) else: if is_translation_request: return Response( - content=json.dumps( # mutable-ok: JSON encoder requires the endpoint error payload mapping - {"error": "Token is not valid for this Realtime endpoint"} - ), + content=json.dumps({"error": "Token is not valid for this Realtime endpoint"}), status_code=http_status.HTTP_401_UNAUTHORIZED, media_type="application/json", ) diff --git a/litellm/realtime_api/main.py b/litellm/realtime_api/main.py index 05a41bf5844..9ac86177fd7 100644 --- a/litellm/realtime_api/main.py +++ b/litellm/realtime_api/main.py @@ -75,12 +75,14 @@ def _with_resolved_session_model(session: dict[str, object], model_name: str) -> audio = session.get("audio") audio = audio if isinstance(audio, dict) else {} # mutable-ok: nested session model is rebuilt locally audio_input = audio.get("input") - audio_input = ( # mutable-ok: nested session model is rebuilt locally - audio_input if isinstance(audio_input, dict) else {} + audio_input = ( + audio_input if isinstance(audio_input, dict) else {} # mutable-ok: nested session model is rebuilt locally ) transcription = audio_input.get("transcription") - transcription = ( # mutable-ok: nested session model is rebuilt locally - transcription if isinstance(transcription, dict) else {} + transcription = ( + transcription + if isinstance(transcription, dict) + else {} # mutable-ok: nested session model is rebuilt locally ) return { # mutable-ok: provider routing requires an independently mutable session payload **session,