From 6bb8e6ab3c6b3217d2c53e8971d5dfce93d51e38 Mon Sep 17 00:00:00 2001 From: Andrew Yim Date: Tue, 28 Apr 2026 07:45:44 +0900 Subject: [PATCH] fix(notion-search): tighten cache type hints + deterministic TTL=0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code review polish: - Type hints: List → List[Dict[str, Any]] for cache_get return and cache_put results parameter, since rerank produces dict-shaped entries. - TTL=0 short-circuits to None deterministically. Previously the test for ttl_seconds=0 passed only because clock motion between cache_put and cache_get made `time.time() - cached_at > 0` true. Now the semantics match the docstring intent. 8/8 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../31-notion-organizer/code/scripts/_search_cache.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/custom-skills/31-notion-organizer/code/scripts/_search_cache.py b/custom-skills/31-notion-organizer/code/scripts/_search_cache.py index 4290703..b3d00e1 100644 --- a/custom-skills/31-notion-organizer/code/scripts/_search_cache.py +++ b/custom-skills/31-notion-organizer/code/scripts/_search_cache.py @@ -6,7 +6,7 @@ import hashlib import json import time from pathlib import Path -from typing import List, Optional +from typing import Any, Dict, List, Optional DEFAULT_CACHE_DIR = Path.home() / ".cache" / "notion-search" DEFAULT_TTL_SECONDS = 86400 # 24 hours @@ -23,11 +23,15 @@ def cache_get( *, cache_dir: Path = DEFAULT_CACHE_DIR, ttl_seconds: int = DEFAULT_TTL_SECONDS, -) -> Optional[List]: +) -> Optional[List[Dict[str, Any]]]: """Return cached results if file exists and is fresh, else None. Corrupted cache files are silently treated as misses (and removed). + `ttl_seconds <= 0` always returns None (deterministic "always expired"). """ + if ttl_seconds <= 0: + return None + key = _cache_key(query, candidate_ids) path = cache_dir / f"{key}.json" if not path.exists(): @@ -52,7 +56,7 @@ def cache_get( def cache_put( query: str, candidate_ids: List[str], - results: List, + results: List[Dict[str, Any]], *, cache_dir: Path = DEFAULT_CACHE_DIR, ) -> None: