1515import sys
1616import tarfile
1717import tempfile
18- from typing import TYPE_CHECKING
18+ from typing import TYPE_CHECKING , Any , TypeIs
1919
2020if TYPE_CHECKING :
2121 from collections .abc import Iterable , Iterator
@@ -33,6 +33,26 @@ def log_level(verbosity: int) -> int:
3333 return logging .DEBUG
3434
3535
36+ def is_str_list (val : Any ) -> TypeIs [list [str ]]: # noqa: ANN401
37+ if not isinstance (val , list ):
38+ return False
39+ return all (isinstance (item , str ) for item in val ) # pyright: ignore[reportUnknownVariableType]
40+
41+
42+ def load_inputs_db (inputs_db_file : pathlib .Path ) -> list [str ]:
43+ if not inputs_db_file .exists ():
44+ return []
45+
46+ with inputs_db_file .open ("r" ) as f :
47+ data = json .load (f )
48+
49+ if not is_str_list (data ):
50+ msg = f"Invalid inputs.json file: expected list of strings, got { data } "
51+ raise TypeError (msg )
52+
53+ return data
54+
55+
3656def move_file_to_local_directory (
3757 file : pathlib .Path , repo_root : pathlib .Path , target_file_name : str
3858) -> bool :
@@ -52,11 +72,7 @@ def move_file_to_local_directory(
5272class FileRecords :
5373 def __init__ (self , repo_root : pathlib .Path ) -> None :
5474 self ._inputs_db_file = repo_root / "inputs.json"
55- if self ._inputs_db_file .exists ():
56- with self ._inputs_db_file .open ("r" ) as f :
57- self ._inputs_db = json .load (f )
58- else :
59- self ._inputs_db = []
75+ self ._inputs_db = load_inputs_db (self ._inputs_db_file )
6076
6177 def contains (self , target_file_name : str ) -> bool :
6278 return target_file_name in self ._inputs_db
0 commit comments