From 21c6451335997f23f8137e2bda606840ad8bc288 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Sat, 14 Feb 2026 18:49:20 -0300 Subject: [PATCH] fix(mypy): use type cast to resolve assignment type errors MyPy was complaining about assigning Optional[str] to str variables. Added type casts after handler calls since model is validated to be non-None at function entry and handlers preserve it. This resolves: - litellm_core_utils/get_llm_provider_logic.py:153: error - litellm_core_utils/get_llm_provider_logic.py:157: error --- litellm/litellm_core_utils/get_llm_provider_logic.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py index 0a569dcea34..ee54c0ed77c 100644 --- a/litellm/litellm_core_utils/get_llm_provider_logic.py +++ b/litellm/litellm_core_utils/get_llm_provider_logic.py @@ -1,4 +1,4 @@ -from typing import Optional, Tuple +from typing import Optional, Tuple, cast import litellm from litellm.constants import REPLICATE_MODEL_NAME_WITH_ID_LENGTH @@ -146,13 +146,19 @@ def get_llm_provider( # noqa: PLR0915 return model, custom_llm_provider, dynamic_api_key, api_base ### Handle cases when custom_llm_provider is set to cohere/command-r-plus but it should use cohere_chat route - model, custom_llm_provider = handle_cohere_chat_model_custom_llm_provider( + _model, _custom_llm_provider = handle_cohere_chat_model_custom_llm_provider( model, custom_llm_provider ) + # model is validated at function entry and handlers preserve it + model = cast(str, _model) + custom_llm_provider = _custom_llm_provider - model, custom_llm_provider = handle_anthropic_text_model_custom_llm_provider( + _model, _custom_llm_provider = handle_anthropic_text_model_custom_llm_provider( model, custom_llm_provider ) + # model is validated at function entry and handlers preserve it + model = cast(str, _model) + custom_llm_provider = _custom_llm_provider if custom_llm_provider and ( model.split("/")[0] != custom_llm_provider