Skip to content

mypy/build: Use _load_json_file in load_tree #11575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,9 @@ def _load_json_file(file: str, manager: BuildManager,
if manager.verbosity() >= 2:
manager.trace(log_success + data.rstrip())
try:
t1 = time.time()
result = json.loads(data)
manager.add_stats(data_json_load_time=time.time() - t1)
except json.JSONDecodeError:
manager.errors.set_file(file, None)
manager.errors.report(-1, -1,
Expand Down Expand Up @@ -1978,17 +1980,17 @@ def load_fine_grained_deps(self) -> Dict[str, Set[str]]:
def load_tree(self, temporary: bool = False) -> None:
assert self.meta is not None, "Internal error: this method must be called only" \
" for cached modules"

data = _load_json_file(self.meta.data_json, self.manager, "Load tree ",
"Could not load tree: ")
if data is None:
return None

t0 = time.time()
raw = self.manager.metastore.read(self.meta.data_json)
t1 = time.time()
data = json.loads(raw)
t2 = time.time()
# TODO: Assert data file wasn't changed.
self.tree = MypyFile.deserialize(data)
t3 = time.time()
self.manager.add_stats(data_read_time=t1 - t0,
data_json_load_time=t2 - t1,
deserialize_time=t3 - t2)
t1 = time.time()
self.manager.add_stats(deserialize_time=t1 - t0)
if not temporary:
self.manager.modules[self.id] = self.tree
self.manager.add_stats(fresh_trees=1)
Expand Down