Skip to content

Report ranges for ignore-without-code errors - #21857

Open
Hmanbo wants to merge 1 commit into
python:masterfrom
Hmanbo:fix-ignore-without-code-position
Open

Report ranges for ignore-without-code errors#21857
Hmanbo wants to merge 1 commit into
python:masterfrom
Hmanbo:fix-ignore-without-code-position

Conversation

@Hmanbo

@Hmanbo Hmanbo commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #21856.

ignore-without-code errors were emitted with report_simple_error(), which always used unknown columns. This change locates actual # type: ignore comment 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-code is enabled, so mypy -c and 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: ignore inside 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 mypy suite 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.

Locate type ignore comments in source and attach their ranges to the
synthesized diagnostic.

Fixes python#21856.
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mypy does not report column and error end for ignore-without-code

1 participant