Skip to content

Commit 427eeee

Browse files
woodruffwtushar-deepsource
authored andcommitted
mypy/build: Use _load_json_file in load_tree (python#11575)
1 parent 713df5e commit 427eeee

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

mypy/build.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,9 @@ def _load_json_file(file: str, manager: BuildManager,
10961096
if manager.verbosity() >= 2:
10971097
manager.trace(log_success + data.rstrip())
10981098
try:
1099+
t1 = time.time()
10991100
result = json.loads(data)
1101+
manager.add_stats(data_json_load_time=time.time() - t1)
11001102
except json.JSONDecodeError:
11011103
manager.errors.set_file(file, None)
11021104
manager.errors.report(-1, -1,
@@ -1979,17 +1981,17 @@ def load_fine_grained_deps(self) -> Dict[str, Set[str]]:
19791981
def load_tree(self, temporary: bool = False) -> None:
19801982
assert self.meta is not None, "Internal error: this method must be called only" \
19811983
" for cached modules"
1984+
1985+
data = _load_json_file(self.meta.data_json, self.manager, "Load tree ",
1986+
"Could not load tree: ")
1987+
if data is None:
1988+
return None
1989+
19821990
t0 = time.time()
1983-
raw = self.manager.metastore.read(self.meta.data_json)
1984-
t1 = time.time()
1985-
data = json.loads(raw)
1986-
t2 = time.time()
19871991
# TODO: Assert data file wasn't changed.
19881992
self.tree = MypyFile.deserialize(data)
1989-
t3 = time.time()
1990-
self.manager.add_stats(data_read_time=t1 - t0,
1991-
data_json_load_time=t2 - t1,
1992-
deserialize_time=t3 - t2)
1993+
t1 = time.time()
1994+
self.manager.add_stats(deserialize_time=t1 - t0)
19931995
if not temporary:
19941996
self.manager.modules[self.id] = self.tree
19951997
self.manager.add_stats(fresh_trees=1)

0 commit comments

Comments
 (0)