

mypy/build: Use` _load_json_file` in `load_tree` by woodruffw · Pull Request #11...
source link: https://github.com/python/mypy/pull/11575
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Conversation
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:
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/usr/local/lib/python3.8/dist-packages/mypy/__main__.py", line 11, in console_entry
main(None, sys.stdout, sys.stderr)
File "mypy/main.py", line 87, in main
File "mypy/main.py", line 165, in run_build
File "mypy/build.py", line 179, in build
File "mypy/build.py", line 254, in _build
File "mypy/build.py", line 2697, in dispatch
File "mypy/build.py", line 3014, in process_graph
File "mypy/build.py", line 3089, in process_fresh_modules
File "mypy/build.py", line 1975, in load_tree
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 5069 (char 5068)
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
Recommend
-
8
New issue README: fix a small formatting typo #91
-
9
Copy link Contributor woodruffw
-
7
Copy link Contributor Author woodru...
-
11
New issue dwarf: initial DWARFv5 support #363
-
14
Copy link Contributor Author woodru...
-
9
New issue Support LLVM_LINK_FLAGS #51
-
7
New issue api-reference/json: document vulnerabilities in responses #10431
-
6
Copy link Contributor woodruffw
-
9
Copy link Contributor woodruffw
-
7
Copy link Contributor woodruffw
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK