Skip to content

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

Open

Description

@A5rocks

Bug Report

ATM import-not-found seems to only trigger for the first import, and therefore can be silenced in a file with multiple imports with a single type ignore. This is... reasonable by itself, but caused me some surprise!

To Reproduce

try:
    import someweirdpackage
except ImportError:
    import someweirdpackage  # type: ignore[import-not-found]

Expected Behavior

Type error on line 2.

Actual Behavior

Only has a type error on line 2 if using the native parser!?!

Your Environment

  • Mypy version used: 2.4.0
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.13.13

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions