Use an immutable empty mapping for the litellm_params fallback

The type-discipline gate flags an inline {} as a mutable construction
(LIT002). Hoist it to a module-level MappingProxyType, matching
_NO_SESSION_KWARGS in router.py.
This commit is contained in:
CaptainAni187 2026-09-09 21:36:05 +05:30
parent 3c1ddbc604
commit 7fcf2c54ba

View file

@ -12,6 +12,7 @@ is logged the first time such a deployment is seen.
import contextlib
from collections.abc import Mapping
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Final
import httpx
@ -47,6 +48,9 @@ class RoutingArgs:
ttl: int = 60 # 1min (RPM/TPM expire key)
_NO_LITELLM_PARAMS: Final[Mapping[str, Any]] = MappingProxyType({})
class ModelRateLimitingCheck(CustomLogger):
"""
Pre-call check that enforces TPM/RPM or ITPM/OTPM limits on model deployments.
@ -314,7 +318,7 @@ class ModelRateLimitingCheck(CustomLogger):
``model_info`` in, so ``model_id`` comes back as "". The router does
stamp ``kwargs["model_info"]``, so prefer that before giving up.
"""
litellm_params: Final = kwargs.get("litellm_params") or {}
litellm_params: Final = kwargs.get("litellm_params") or _NO_LITELLM_PARAMS
for source in (kwargs.get("model_info"), litellm_params.get("model_info")):
if isinstance(source, Mapping):
candidate = source.get("id")