Skip to content

Commit 6e1f468

Browse files
committed
Ensure caching works if there is no pre-existing data
1 parent 935dca0 commit 6e1f468

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

scripts/element_tracking.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ class ElementsInProgress:
5252
mappings of tasks that are known to be equivalent to those in this repo.
5353
"""
5454

55-
def __init__(self, known_elements: Optional[MutableMapping[str, int]]) -> None:
56-
self.known_elements = known_elements or {}
55+
def __init__(self, known_elements: MutableMapping[str, int]) -> None:
56+
# Note: it's important that we use the mapping the user passes in so
57+
# that they can pass an object that will keep track of the elements that
58+
# have been processed (either a `shelve` or the mapping yielded by an
59+
# `ElementsCache` instance work well).
60+
self.known_elements = known_elements
5761
self._current: Set[str] = set()
5862

5963
def get(self, key: str) -> Optional[int]:

scripts/import.py

Lines changed: 2 additions & 2 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, MutableMapping, Optional
6+
from typing import TYPE_CHECKING, Callable, MutableMapping
77

88
import yaml
99
from element_tracking import ElementsCache, ElementsInProgress
@@ -86,7 +86,7 @@ def add(
8686
backend: 'Backend',
8787
year: str,
8888
*,
89-
known_elements: Optional[MutableMapping[str, int]] = None,
89+
known_elements: MutableMapping[str, int],
9090
) -> int:
9191
"""
9292
Add 'element' into the task tracker, along with all its dependencies.

0 commit comments

Comments
 (0)