From 5272920fa0daab676f5ad46dcadd8cd537cfc96f Mon Sep 17 00:00:00 2001 From: michaelxer Date: Mon, 15 Jun 2026 21:17:32 +0700 Subject: [PATCH] fix: update type annotations for check_and_fix_namespace - Change signature from str -> str to Optional[str] -> Optional[str] - Remove type: ignore comment on None return - Add None guard in async_set_cache_sadd before passing to helper Addresses review feedback from Sameerlite on type mismatch. --- litellm/caching/redis_cache.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/caching/redis_cache.py b/litellm/caching/redis_cache.py index 263e1df2ee7..a6401b9dc6d 100644 --- a/litellm/caching/redis_cache.py +++ b/litellm/caching/redis_cache.py @@ -365,12 +365,13 @@ class RedisCache(BaseCache): self.redis_async_client = redis_async_client # type: ignore return redis_async_client - def check_and_fix_namespace(self, key: str) -> str: + def check_and_fix_namespace(self, key: Optional[str]) -> Optional[str]: """ - Make sure each key starts with the given namespace + Make sure each key starts with the given namespace. + Returns None if key is None (caller is responsible for guarding). """ if key is None: - return key # type: ignore[return-value] + return None if self.namespace is not None and not key.startswith(self.namespace): key = self.namespace + ":" + key @@ -790,6 +791,8 @@ class RedisCache(BaseCache): raise e key = self.check_and_fix_namespace(key=key) + if key is None: + return print_verbose(f"Set ASYNC Redis Cache: key: {key}\nValue {value}\nttl={ttl}") try: await self._set_cache_sadd_helper(