fix(types): keep the token-limit predicate's mapping access fully typed

The new `_deployment_token_limits_configured` reads two keys off a bare
`Mapping`, so both `.get` member accesses are only partially known and
reportUnknownMemberType lands two over its ceiling on the basedpyright
delta gate. Pin the value type with a cast before reading the keys.

Checked with basedpyright 1.40.2 on litellm/router.py:
reportUnknownMemberType 1530 -> 1528, reportExplicitAny unchanged at 28.
This commit is contained in:
RichardoMu 2026-10-12 15:00:55 +08:00
parent f39ee4aa22
commit eee62875ae

View file

@ -10775,7 +10775,14 @@ class Router:
"""
if not isinstance(model_info, Mapping):
return False
return model_info.get("max_input_tokens") is not None and model_info.get("max_output_tokens") is not None
# ``Mapping`` is unparameterised here, so pin the key/value types before
# reading the keys: bare ``Mapping`` makes both ``.get`` member accesses
# only partially known, which trips the basedpyright delta gate.
typed_model_info: Final = cast(Mapping[str, object], model_info) # cast-ok: isinstance check above
return (
typed_model_info.get("max_input_tokens") is not None
and typed_model_info.get("max_output_tokens") is not None
)
async def arefresh_model_info(self, *, client: AsyncHTTPHandler | None = None) -> None:
"""Refresh token limits advertised by configured OpenAI-compatible deployments."""