CLAUDE: Fix type annotations in CacheManager for JSON-serializable types
Update CacheManager.get() and CacheManager.set() type annotations to accept Any JSON-serializable type (dict, list, str, int, bool, None) instead of just dict. This fixes type checker warnings in base_service.py where lists are cached for API responses. The runtime behavior was already correct, this just aligns the type hints with actual usage. Changes: - CacheManager.get() return type: Optional[dict] -> Optional[Any] - CacheManager.set() data param: dict -> Any - Updated docstrings to clarify JSON-serializable types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
68c30e565b
commit
2e1e3361a1
@ -4,7 +4,7 @@ Redis caching utilities for Discord Bot v2.0
|
|||||||
Provides optional Redis caching functionality for API responses.
|
Provides optional Redis caching functionality for API responses.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional, Any
|
||||||
import json
|
import json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -108,15 +108,15 @@ class CacheManager:
|
|||||||
"""
|
"""
|
||||||
return f"{prefix}:{identifier}"
|
return f"{prefix}:{identifier}"
|
||||||
|
|
||||||
async def get(self, key: str) -> Optional[dict]:
|
async def get(self, key: str) -> Optional[Any]:
|
||||||
"""
|
"""
|
||||||
Get cached data.
|
Get cached data.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
key: Cache key
|
key: Cache key
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Cached data as dict or None if not found/error
|
Cached data (any JSON-serializable type) or None if not found/error
|
||||||
"""
|
"""
|
||||||
client = await self._get_client()
|
client = await self._get_client()
|
||||||
if not client:
|
if not client:
|
||||||
@ -134,13 +134,13 @@ class CacheManager:
|
|||||||
logger.debug(f"Cache miss: {key}")
|
logger.debug(f"Cache miss: {key}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def set(self, key: str, data: dict, ttl: Optional[int] = None) -> None:
|
async def set(self, key: str, data: Any, ttl: Optional[int] = None) -> None:
|
||||||
"""
|
"""
|
||||||
Set cached data.
|
Set cached data.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
key: Cache key
|
key: Cache key
|
||||||
data: Data to cache (must be JSON serializable)
|
data: Data to cache (any JSON-serializable type: dict, list, str, int, bool, None)
|
||||||
ttl: Time-to-live override (uses default if None)
|
ttl: Time-to-live override (uses default if None)
|
||||||
"""
|
"""
|
||||||
client = await self._get_client()
|
client = await self._get_client()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user