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>
This commit is contained in:
Kylinny 2026-10-14 11:55:57 +00:00 • committed by Kylinny
parent da0b57652b
commit 56e74cd4d9
2 changed files with 15 additions and 15 deletions

View file

@ -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,

View file

@ -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