From fd2fce1323d078c6aa99b01cafc901e9c0304c96 Mon Sep 17 00:00:00 2001 From: Chengxuan Wang Date: Wed, 17 Jun 2026 21:22:17 -0700 Subject: [PATCH] fix(lint): use X | None over Optional in mid-stream helper (UP045) Rebased onto current litellm_internal_staging, whose strict-rule budget now tracks UP045 (non-pep604 annotations). Convert the 4 Optional[...] annotations the helper added to X | None so the change stays within budget. --- litellm/router_utils/fallback_event_handlers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/litellm/router_utils/fallback_event_handlers.py b/litellm/router_utils/fallback_event_handlers.py index 2461f907bef..b8ebdacddb4 100644 --- a/litellm/router_utils/fallback_event_handlers.py +++ b/litellm/router_utils/fallback_event_handlers.py @@ -20,7 +20,7 @@ else: MID_STREAM_CONTINUATION_SYSTEM_PROMPT = "You are a helpful assistant. You are given a message and you need to respond to it. You are also given a generated content. You need to respond to the message in continuation of the generated content. Do not repeat the same content. Your response should be in continuation of this text: " -def _prefill_explicitly_unsupported(model_group: Optional[str]) -> bool: +def _prefill_explicitly_unsupported(model_group: str | None) -> bool: """True only when the model registry explicitly marks the model as NOT supporting assistant prefill (``supports_assistant_prefill: false``). @@ -42,8 +42,8 @@ def _prefill_explicitly_unsupported(model_group: Optional[str]) -> bool: def build_mid_stream_continuation_messages( messages: list[Any], generated_content: str, - model_group: Optional[str], - fallbacks: Optional[list[Any]] = None, + model_group: str | None, + fallbacks: list[Any] | None = None, ) -> list[Any]: """Build the message list a mid-stream fallback uses to resume an interrupted stream. @@ -63,7 +63,7 @@ def build_mid_stream_continuation_messages( configured fallback target for this model group is explicitly marked as not supporting prefill. """ - candidate_models: list[Optional[str]] = [model_group] + candidate_models: list[str | None] = [model_group] if fallbacks is not None and model_group is not None: if fallbacks and all(isinstance(f, str) for f in fallbacks): # Flat string-format lists (["model-a", "model-b", ...]) are tried in