Skip to content

Commit 7ffd805

Browse files
Allow scalar JSON cache entries
Amp-Thread-ID: https://ampcode.com/threads/T-019e497d-a5a0-77b0-a8bb-fa8abc74113a Co-authored-by: Amp <amp@ampcode.com>
1 parent 010e8e3 commit 7ffd805

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/src_py_lib/utils/json_cache.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
import json
66
from collections.abc import Callable, Mapping
77
from pathlib import Path
8-
from typing import cast
9-
10-
from src_py_lib.utils.json_types import JSONDict
8+
from typing import Any, cast
119

1210

1311
def load_json_cache[Entry](
1412
path: Path,
15-
parse: Callable[[JSONDict], Entry] | None = None,
13+
parse: Callable[[Any], Entry] | None = None,
1614
) -> dict[str, Entry]:
1715
"""Load `path` as a string-keyed cache. Missing files return `{}`."""
1816
if not path.exists():
1917
return {}
20-
raw = cast(dict[str, JSONDict], json.loads(path.read_text(encoding="utf-8")))
18+
raw = cast(dict[str, Any], json.loads(path.read_text(encoding="utf-8")))
2119
if parse is None:
2220
return cast(dict[str, Entry], raw)
2321
return {key: parse(value) for key, value in raw.items()}
@@ -32,7 +30,7 @@ def save_json_cache(path: Path, cache: Mapping[str, object]) -> None:
3230
def load_json_subset[Entry](
3331
path: Path,
3432
keys: list[str],
35-
parse: Callable[[JSONDict], Entry] | None = None,
33+
parse: Callable[[Any], Entry] | None = None,
3634
) -> dict[str, Entry]:
3735
"""Load only `keys` that are present in a string-keyed JSON cache."""
3836
cache = load_json_cache(path, parse=parse)

0 commit comments

Comments
 (0)