Skip to content

Preserve import order in legacy parser try blocks - #22272

Open
zhengguangzhuo wants to merge 2 commits into
python:masterfrom
zhengguangzhuo:zhengguangzhuo/mypy-import-ignore-22260
Open

zhengguangzhuo wants to merge 2 commits into
python:masterfrom
zhengguangzhuo:zhengguangzhuo/mypy-import-ignore-22260

Conversation

@zhengguangzhuo

Copy link
Copy Markdown

Summary

  • Preserve source order when the legacy parser converts try and try* statements, so duplicate imports use the first source occurrence when selecting a diagnostic location.
  • Add regression coverage for the native and legacy parsers when an unignored missing import is followed by a type-ignored retry.

Closes #22260.

Verification

  • .venv\Scripts\python.exe -m pytest -n0 -q -k testRepeatedMissingImportKeepsFirstUnsuppressedError — 2 passed.
  • .venv\Scripts\python.exe -m pytest -n0 -q -k 'check-modules.test' — 251 passed.
  • git diff --check — passed.

This change was prepared with OpenAI Codex assistance. The account holder should review the change before merge.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

sphinx (https://github.com/sphinx-doc/sphinx)
- sphinx/testing/util.py:80:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

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.

import-not-found should be reported for the first non-type-ignored import

1 participant