fix(cache): satisfy current type and lint gates

This commit is contained in:
Maximilian Rink 2026-10-15 09:08:10 +02:00
parent d1acdfaf9a
commit 64c6dbf85f
3 changed files with 10 additions and 7 deletions

View file

@ -848,7 +848,7 @@ class Cache:
else:
cache_key = self.get_cache_key(**kwargs) # rebind-ok: derive caller key
if cache_key is not None:
cache_control_args: Final[DynamicCacheControl] = kwargs.get("cache", {})
cache_control_args: Final[DynamicCacheControl] = cast(DynamicCacheControl, kwargs.get("cache", {}))
max_age = cache_control_args.get("s-maxage") or cache_control_args.get("s-max-age") or float("inf")
cache_lookup_kwargs: Final = self._get_safe_cache_lookup_kwargs(kwargs)
if dynamic_cache_object is not None:
@ -883,7 +883,7 @@ class Cache:
else:
cache_key = self.get_cache_key(**kwargs) # rebind-ok: derive caller key
if cache_key is not None:
cache_control_args: Final = kwargs.get("cache", {})
cache_control_args: Final[DynamicCacheControl] = cast(DynamicCacheControl, kwargs.get("cache", {}))
max_age: Final = cache_control_args.get(
"s-max-age", cache_control_args.get("s-maxage", float("inf"))
)
@ -956,7 +956,7 @@ class Cache:
return
verbose_logger.error("%s: %s", message, exc)
async def async_add_cache(self, result, dynamic_cache_object: BaseCache | None = None, **kwargs):
async def async_add_cache(self, result: object, dynamic_cache_object: BaseCache | None = None, **kwargs: object):
"""
Async implementation of add_cache
"""

View file

@ -4,7 +4,7 @@
### [BETA] this is in Beta. And might change.
import traceback
from typing import Final, Literal
from typing import Final, Literal, cast # noqa: TID251 # typed cache kwargs boundary
from fastapi import HTTPException
@ -106,7 +106,7 @@ class _PROXY_BatchRedisRequests(CustomLogger):
) # returns "<cache_key_name>:<hash>" - we pass redis_namespace in async_pre_call_hook. Done to avoid rewriting the async_set_cache logic
if cache_key is not None and self.in_memory_cache is not None:
cache_control_args: Final = kwargs.get("cache", {})
cache_control_args: Final[DynamicCacheControl] = cast(DynamicCacheControl, kwargs.get("cache", {}))
max_age: Final = cache_control_args.get("s-max-age", cache_control_args.get("s-maxage", float("inf")))
cached_result = self.in_memory_cache.get_cache(cache_key, *args, **kwargs)
if cached_result is None:

View file

@ -610,7 +610,10 @@ def get_logging_payload(
elif not isinstance(response_obj, BaseModel) and not isinstance(response_obj, dict):
response_obj = {"result": str(response_obj)}
# standardize this function to be used across, s3, dynamoDB, langfuse logging
litellm_params: Final = kwargs.get("litellm_params", {})
litellm_params_value: Final[object] = kwargs.get("litellm_params", {})
litellm_params: Final[dict[str, object]] = (
cast(dict[str, object], litellm_params_value) if isinstance(litellm_params_value, Mapping) else {}
)
metadata: Final = get_litellm_metadata_from_kwargs(kwargs)
routing_litellm_params: Final[Mapping[str, object] | None] = (
litellm_params if isinstance(litellm_params, Mapping) else None
@ -880,7 +883,7 @@ def get_logging_payload(
metadata=metadata,
requested_model=persisted_model_group,
selected_model=model_name,
selected_provider=custom_llm_provider,
selected_provider=(custom_llm_provider if isinstance(custom_llm_provider, str) else None),
router_correlation_id=litellm_call_id,
),
used_client_oauth_token=resolve_used_client_oauth_token(