Skip to content

# type: ignore[import] at top of file causes all error codes to be ignored #11999

Closed

Description

@cool-RR

Windows 7, Mypy 0.931, Python 3.8.10

An # type: ignore[import] line at top of file causes all error codes to be ignored, not just that error code.

I'm guessing this was never supposed to work, and is just a side effect of #964. However, (1) this is too confusing and easy-to-miss, (2) this feature would be very useful in my opinion. Sometimes there's just this one error that comes up lots of times in a file and I want to shush just that one without losing the other warnings.

Administrator@Turing MSYS ~/Desktop
$ cat x.py
import numpy

def f(x: str = 3):
    return 7
Administrator@Turing MSYS ~/Desktop
$ mypy x.py --show-error-codes
x.py:1: error: Skipping analyzing "numpy": module is installed, but missing library stubs or py.typed
 marker  [import]
x.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
x.py:3: error: Incompatible default for argument "x" (default has type "int", argument has type "str"
)  [assignment]
Found 2 errors in 1 file (checked 1 source file)

Administrator@Turing MSYS ~/Desktop
$ cat y.py
# type: ignore[import]
import numpy

def f(x: str = 3):
    return 7
Administrator@Turing MSYS ~/Desktop
$ mypy y.py --show-error-codes
Success: no issues found in 1 source file

Activity

  1. A5rocks commented on Jan 22, 2022

    @A5rocks
    Collaborator

    For imports at least, configuration files offer some customization, though this might just generally be useful. (especially if mypy gets proper error codes).

  2. added a commit that references this issue on Aug 25, 2022
    9dd525d
  3. added a commit that references this issue on Aug 26, 2022
    da56c97
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 wrongtopic-type-ignore# type: ignore comments

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions