mypy/build: Use _load_json_file
in load_tree
#11575
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is a variant of #6156, albeit not the same exact failure site.
In one of my professional projects, we use
mypy
to lint a relatively complex Python codebase. For reasons that haven't been fully root-caused, we occasionally see JSON corruption errors that look like this:That's with the latest MyPy (0.910), Python 3.8, Ubuntu 20.04. Note that the error here happens in
load_tree
and not_load_json_file
.We're not 100% sure what causes this error, but we do know how to make the error more comprehensible: by reusing the error handling functionality that's already been added to
_load_json_file
with #6156. So, that's all this PR does: it reuses that utility function to turn the uncontrolled exception into something more recognizable as a MyPy cache error.Test Plan
I haven't made any test changes, but I've confirmed that the test suite passes locally with the functional changes that I've applied:
source venv/bin/activate python3 runtests.py