Repository navigation
Report a clean error for corrupt cache instead of INTERNAL ERROR - #22223
Open
inchang-ing wants to merge 2 commits into
Open
inchang-ing wants to merge 2 commits into
inchang-ing wants to merge 2 commits into
Conversation
When the mypy cache is corrupt (e.g. partially overwritten), mypy used to crash with an INTERNAL ERROR. Now it reports an actionable error that tells the user to remove the cache directory (or pass a different --cache-dir) and re-run. This covers corruption detected while reading/deserializing the cache data file, while resolving cache metadata, while fixing cross-references after deserialization, and the deferred "TypeInfo not fixed" assertion that would otherwise surface deep inside type checking. Fixes python#22220
for more information, see https://pre-commit.ci
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: scipy-stubs (https://github.com/scipy/scipy-stubs)
+ tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When the mypy cache is corrupt (for example, partially overwritten in a shared/temp directory), mypy used to crash with an
INTERNAL ERROR. This PR replaces that with an actionable error telling the user to remove the cache directory (or pass a different--cache-dir) and re-run.Fixes #22220
How it works
The fix adds guards on every cache-read path in
mypy/build.py:State.load_tree) — the most common corruption case (a garbage/trucated.data.ff).CacheMeta.read/CacheMeta.deserializeandCacheMetaEx).State.fix_cross_refs), where a missing type reference used to raise during fix-up.AssertionError(NOT_READYplaceholder) that otherwise surfaced deep inside type checking, caught inState.wrap_context.All paths now report a blocker error such as:
Reproduction / verification
Before the fix, a corrupt cache produces:
After the fix:
A new regression test (
mypy/test/testcache.py) populates the cache, corrupts the cached data file (preserving mtime so the cache is still trusted), and asserts the next build fails with a clean "corrupt cache" error and without anINTERNAL ERROR. The test fails on the unguarded code (rawAssertionError/INTERNAL ERROR) and passes with the fix.Test plan
python -m pytest mypy/test/testcache.py -n0— new test passes.python -m pytest mypy/test/testmerge.py -n0— existing cache/merge tests pass (no regression).