Report ranges for ignore-without-code errors - #21857
Open
Hmanbo wants to merge 1 commit into
Open
Conversation
Locate type ignore comments in source and attach their ranges to the synthesized diagnostic. Fixes python#21856.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Fixes #21856.
ignore-without-codeerrors were emitted withreport_simple_error(), which always used unknown columns. This change locates actual# type: ignorecomment tokens in the checked source and passes their start and end columns to the synthesized diagnostic.The source ranges are cached per file and invalidated when a file is reprocessed. In-memory sources are retained only when
ignore-without-codeis enabled, somypy -cand data-driven tests receive the same location information as filesystem sources.The regression test covers both the reported assignment case and a line containing
# type: ignoreinside a string before the actual comment.Validation:
pytest -n0 -q mypy/test/testcheck.py::TypeCheckSuite::check-columns.test mypy/test/testcheck.py::TypeCheckSuite::check-errorcodes.test(175 passed)pytest -n0 -q -k TypeIgnoreWithoutCodePreservedOnRerun mypy/test/testdaemon.py(1 passed)python runtests.py self(success across 341 source files)pre-commit run --files mypy/build.py mypy/errors.py test-data/unit/check-columns.test(all applicable hooks passed)The complete
pytest -q mypysuite was also started locally, but did not finish within a 10-minute command limit; CI should provide the complete platform matrix.This change was developed with assistance from OpenAI Codex and reviewed and tested locally.