From b68c1fa8fe0243d9111f51fa37cd58068a6895e5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 6 Aug 2026 00:06:37 +0000 Subject: [PATCH] refactor: single canonical DateTimeEncoder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/cache_manager.py and src/cache/disk_cache.py each defined an identical DateTimeEncoder (datetime -> ISO-8601). The disk_cache copy is the only one actually used for serialization; cache_manager now re-exports it instead of defining a twin, so the two can never silently diverge. Import compatibility is preserved — from src.cache_manager import DateTimeEncoder still works and is the same class object. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01SXb4mKcAkVaxkeTb3YnAdr --- src/cache_manager.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/cache_manager.py b/src/cache_manager.py index 5065dcdb..20a3cfd7 100644 --- a/src/cache_manager.py +++ b/src/cache_manager.py @@ -39,14 +39,10 @@ from src.cache.cache_strategy import CacheStrategy from src.cache.cache_metrics import CacheMetrics from src.logging_config import get_logger -class DateTimeEncoder(json.JSONEncoder): - """JSON encoder that serialises ``datetime`` objects as ISO-8601 strings.""" - - def default(self, obj): - """Return ISO-8601 string for datetime; delegate all other types to the base encoder.""" - if isinstance(obj, datetime): - return obj.isoformat() - return super().default(obj) +# Canonical implementation lives in src.cache.disk_cache; re-exported here +# because this module's docstring documents it and external code may import +# it from either path. +from src.cache.disk_cache import DateTimeEncoder class CacheManager: """Manages caching of API responses to reduce API calls."""