Skip to content

Commit d7fa217

Browse files
committed
Clarify usage of the elements cache
1 parent aaf3b7d commit d7fa217

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

scripts/element_tracking.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414

1515

1616
class ElementsCache:
17+
"""
18+
Load and cache the tasks that have been created in a file.
19+
20+
Use like:
21+
```
22+
with ElementsCache(Path('cache.json')) as elements:
23+
elements['key'] = 14
24+
"""
25+
1726
def __init__(self, cache_path: Path) -> None:
1827
self.cache_path = cache_path
1928
self.elements: Dict[str, int] = {}
@@ -23,7 +32,7 @@ def __init__(self, cache_path: Path) -> None:
2332
except IOError:
2433
pass
2534

26-
def __enter__(self) -> Dict[str, int]:
35+
def __enter__(self) -> MutableMapping[str, int]:
2736
return self.elements
2837

2938
def __exit__(

scripts/import.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import argparse
44
import contextlib
55
from pathlib import Path
6-
from typing import TYPE_CHECKING, Callable, Dict, MutableMapping, Optional
6+
from typing import TYPE_CHECKING, Callable, MutableMapping, Optional
77

88
import yaml
99
from element_tracking import ElementsCache, ElementsInProgress
@@ -156,11 +156,11 @@ def main(arguments: argparse.Namespace) -> None:
156156

157157
with contextlib.ExitStack() as stack:
158158
if arguments.cache:
159-
elements: Optional[Dict[str, int]] = stack.enter_context(
159+
elements: MutableMapping[str, int] = stack.enter_context(
160160
ElementsCache(arguments.cache),
161161
)
162162
else:
163-
elements = None
163+
elements = {}
164164

165165
add(arguments.base, backend, arguments.year, known_elements=elements)
166166

0 commit comments

Comments
 (0)