From 3f3254c13e01ea7b3530e2b3078e97324d3db185 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 6 Aug 2026 06:15:09 +0000 Subject: [PATCH] fix(lint): narrow decorator + cache override kwargs types to unblock strict budget gate Adds parameter and return type annotations to _redis_circuit_breaker_guard and UserApiKeyCache write overrides so ANN003/ANN202/ANN001/ANN002 totals fall back below their ruff-strict-budget.json limits. The uv promote-staging to-main lint gate was failing with ANN003 838 over limit 836 and ANN202 870 over limit 869; the annotations bring the counts to 834 and 868. Co-authored-by: Krrish Dholakia --- litellm/caching/redis_cache.py | 6 ++++-- litellm/proxy/common_utils/user_api_key_cache.py | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/litellm/caching/redis_cache.py b/litellm/caching/redis_cache.py index 5fedfc5bcce..f047a6f6f89 100644 --- a/litellm/caching/redis_cache.py +++ b/litellm/caching/redis_cache.py @@ -242,7 +242,9 @@ async def _run_under_circuit_breaker( return result -def _redis_circuit_breaker_guard(method): +def _redis_circuit_breaker_guard( + method: Callable[..., Awaitable[_RedisCallResult]], +) -> Callable[..., Awaitable[_RedisCallResult]]: """ Decorator for RedisCache async methods. Checks the circuit breaker before each call; records success/failure after. @@ -256,7 +258,7 @@ def _redis_circuit_breaker_guard(method): """ @functools.wraps(method) - async def wrapper(self, *args, **kwargs): + async def wrapper(self: "RedisCache", *args: object, **kwargs: object) -> _RedisCallResult: return await _run_under_circuit_breaker( self._circuit_breaker, method.__name__, lambda: method(self, *args, **kwargs) ) diff --git a/litellm/proxy/common_utils/user_api_key_cache.py b/litellm/proxy/common_utils/user_api_key_cache.py index 22c3741d1a2..ead48509ae3 100644 --- a/litellm/proxy/common_utils/user_api_key_cache.py +++ b/litellm/proxy/common_utils/user_api_key_cache.py @@ -129,17 +129,17 @@ class UserApiKeyCache(DualCache): return None return decoded - def set_cache(self, key, value, local_only: bool = False, **kwargs): + def set_cache(self, key, value, local_only: bool = False, **kwargs: object): model_type: Final = cast(type[BaseModel] | None, kwargs.pop("model_type", None)) payload: Final = CacheCodec.serialize(value, model_type=model_type) return super().set_cache(key=key, value=payload, local_only=local_only, **kwargs) - async def async_set_cache(self, key, value, local_only: bool = False, **kwargs): + async def async_set_cache(self, key, value, local_only: bool = False, **kwargs: object): model_type: Final = cast(type[BaseModel] | None, kwargs.pop("model_type", None)) payload: Final = CacheCodec.serialize(value, model_type=model_type) return await super().async_set_cache(key=key, value=payload, local_only=local_only, **kwargs) - async def async_set_cache_pipeline(self, cache_list: list, local_only: bool = False, **kwargs) -> None: + async def async_set_cache_pipeline(self, cache_list: list, local_only: bool = False, **kwargs: object) -> None: """ Batch writes with the same Codec boundary as ``async_set_cache`` without ``model_type``: ``BaseModel`` values become JSON-safe dicts; dicts/scalars unchanged.