From 56e74cd4d99df1cbad9989ba18ccccf7d0a79ede Mon Sep 17 00:00:00 2001 From: Kylinny <64238008+Kylinny@users.noreply.github.com> Date: Wed, 14 Oct 2026 11:55:57 +0000 Subject: [PATCH] fix(router): use dict[str, Any] annotations to satisfy basedpyright delta gate Replace bare dict annotations with dict[str, Any] so the new filter_tool_protocol_deployments code introduces zero new basedpyright errors. Add pyright ignore comments at the two router.py call sites where the untyped router passes bare dicts. No behavior change. Signed-off-by: Kylinny <64238008+Kylinny@users.noreply.github.com> --- litellm/router.py | 10 +++++----- litellm/router_utils/common_utils.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index 1e644433ef2..d13bc5a72ff 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -15040,8 +15040,8 @@ class Router: ) ) healthy_deployments = filter_tool_protocol_deployments( # rebind-ok: progressive narrowing of the candidate list through the router filter pipeline; rebinding is the established pattern in this function - healthy_deployments=healthy_deployments, - request_kwargs=request_kwargs, + healthy_deployments=healthy_deployments, # pyright: ignore[reportUnknownArgumentType] # router passes bare dicts; callee accepts dict[str, Any] + request_kwargs=request_kwargs, # pyright: ignore[reportUnknownArgumentType] # router passes bare dicts; callee accepts dict[str, Any] ) if isinstance(healthy_deployments, dict): @@ -16356,15 +16356,15 @@ class Router: ) healthy_deployments = filter_tool_protocol_deployments( # rebind-ok: progressive narrowing of the candidate list through the router filter pipeline; rebinding is the established pattern in this function - healthy_deployments=healthy_deployments, - request_kwargs=request_kwargs, + healthy_deployments=healthy_deployments, # pyright: ignore[reportUnknownArgumentType] # router passes bare dicts; callee accepts dict[str, Any] + request_kwargs=request_kwargs, # pyright: ignore[reportUnknownArgumentType] # router passes bare dicts; callee accepts dict[str, Any] ) # filter pre-call checks if self.enable_pre_call_checks and (messages is not None or input is not None): healthy_deployments = self._pre_call_checks( model=model, - healthy_deployments=healthy_deployments, + healthy_deployments=healthy_deployments, # pyright: ignore[reportArgumentType] # filtered result stays a bare-dict list for the untyped callee messages=messages, input=input, request_kwargs=request_kwargs, diff --git a/litellm/router_utils/common_utils.py b/litellm/router_utils/common_utils.py index fce256b0707..33da0f05cef 100644 --- a/litellm/router_utils/common_utils.py +++ b/litellm/router_utils/common_utils.py @@ -2,7 +2,7 @@ import hashlib import json from collections.abc import Mapping, Sequence from types import MappingProxyType -from typing import TYPE_CHECKING, Final, TypeVar +from typing import TYPE_CHECKING, Any, Final, TypeVar, cast from pydantic import TypeAdapter @@ -403,12 +403,13 @@ def filter_web_search_deployments( # translation. Same family litellm uses for OpenAI-protocol param handling in # `add_provider_specific_params_to_optional_params` (litellm/utils.py). _OPENAI_NATIVE_PROTOCOL_PROVIDERS: Final = frozenset( - ["openai", "azure", "text-completion-openai"] + litellm.openai_compatible_providers + ["openai", "azure", "text-completion-openai"] + + cast("list[str]", litellm.openai_compatible_providers) # cast-ok: provider names are strings ) -def _deployment_speaks_openai_protocol(deployment: dict) -> bool: # mutable-ok: read-only access, never mutated - litellm_params: Final = deployment.get("litellm_params") or {} +def _deployment_speaks_openai_protocol(deployment: dict[str, Any]) -> bool: # mutable-ok: read-only, never mutated + litellm_params: Final[dict[str, Any]] = deployment.get("litellm_params") or {} # mutable-ok: read-only provider: Final = provider_for_generic_call(litellm_params) if provider is None: return True @@ -416,9 +417,9 @@ def _deployment_speaks_openai_protocol(deployment: dict) -> bool: # mutable-ok: def filter_tool_protocol_deployments( - healthy_deployments: list[dict] | dict, # mutable-ok: mirrors router candidate type; read-only - request_kwargs: dict | None = None, # mutable-ok: OptionalParams dict; read-only -) -> list[dict] | dict: # mutable-ok: returns input or narrowed new list + healthy_deployments: list[dict[str, Any]] | dict[str, Any], # mutable-ok: router candidate type + request_kwargs: dict[str, Any] | None = None, # mutable-ok: OptionalParams dict +) -> list[dict[str, Any]] | dict[str, Any]: # mutable-ok: returns input or narrowed list """ Keep only OpenAI-protocol deployments for OpenAI-format tool-calling requests. @@ -439,10 +440,9 @@ def filter_tool_protocol_deployments( """ if request_kwargs is None or isinstance(healthy_deployments, dict): return healthy_deployments - tools: Final = request_kwargs.get("tools") or [] + tools: Final[list[dict[str, Any]]] = request_kwargs.get("tools") or [] # mutable-ok: read-only is_openai_tool_request: Final = any( - isinstance(tool, dict) and tool.get("type") == "function" and isinstance(tool.get("function"), dict) - for tool in tools + tool.get("type") == "function" and isinstance(tool.get("function"), dict) for tool in tools ) if not is_openai_tool_request: return healthy_deployments