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.
This commit is contained in:
michaelxer 2026-06-15 21:17:32 +07:00
parent 6a93f6e67a
commit 5272920fa0

View file

@ -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(