KEMBAR78
`# type: ignore[import]` at top of file causes all error codes to be ignored · Issue #11999 · python/mypy · GitHub
Skip to content

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

@cool-RR

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

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