Add full type annotations and black formatting across all modules
Annotated all functions with mypy --strict-compatible types (-> None, dict[str, Any], Generator types, etc.), added # type: ignore for untyped third-party libs (lxml), and reformatted with black. All 18 source files now pass mypy --strict with zero errors. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
453d6244ec
commit
13c4341f3a
14 changed files with 1802 additions and 974 deletions
9
cache.py
9
cache.py
|
|
@ -2,16 +2,17 @@ import json
|
|||
import os
|
||||
import time
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
from config.default import CACHE_DIR # overridden by app config after import
|
||||
|
||||
|
||||
def _cache_path(key: str) -> str:
|
||||
safe_key = key.replace('/', '_').replace(' ', '_')
|
||||
safe_key = key.replace("/", "_").replace(" ", "_")
|
||||
return os.path.join(CACHE_DIR, f"{safe_key}.json")
|
||||
|
||||
|
||||
def get_cached(key: str, ttl: int | None = None):
|
||||
def get_cached(key: str, ttl: int | None = None) -> Any:
|
||||
"""Return cached data, or None if missing or older than ttl seconds."""
|
||||
path = _cache_path(key)
|
||||
try:
|
||||
|
|
@ -25,10 +26,10 @@ def get_cached(key: str, ttl: int | None = None):
|
|||
return None
|
||||
|
||||
|
||||
def set_cached(key: str, data) -> None:
|
||||
def set_cached(key: str, data: Any) -> None:
|
||||
os.makedirs(CACHE_DIR, exist_ok=True)
|
||||
path = _cache_path(key)
|
||||
tmp_path = f"{path}.{os.getpid()}.{uuid.uuid4().hex}.tmp"
|
||||
with open(tmp_path, 'w') as f:
|
||||
with open(tmp_path, "w") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
os.replace(tmp_path, path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue