Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cool-RR opened this issue Jan 16, 2022 · 1 comment · Fixed by #13512
Closed

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

cool-RR opened this issue Jan 16, 2022 · 1 comment · Fixed by #13512
Labels
bug mypy got something wrong topic-type-ignore # type: ignore comments

Comments

@cool-RR
Copy link
Contributor

cool-RR commented Jan 16, 2022

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
@cool-RR cool-RR added the bug mypy got something wrong label Jan 16, 2022
@A5rocks
Copy link
Contributor

A5rocks commented Jan 22, 2022

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

@AlexWaygood AlexWaygood added the topic-type-ignore # type: ignore comments label Mar 26, 2022
hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Aug 25, 2022
Per-module error codes were added in python#13502, let's recommend using them.

The existing type ignore behaviour is pretty unintuitive; I think most
people actually want `# mypy: ignore-errors`. There are probably people
depending on the current behaviour though.

Fixes python#13435, fixes python#12076, fixes python#11999, fixes python#11027, fixes python#9318,
fixes python#7839
hauntsaninja added a commit that referenced this issue Aug 26, 2022
Per-module error codes were added in #13502, let's recommend using them.

The existing type ignore behaviour is pretty unintuitive; I think most
people actually want `# mypy: ignore-errors`. There are probably people
depending on the current behaviour though.

Fixes #13435, fixes #12076, fixes #11999, fixes #11027, fixes #9318,
fixes #7839
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-type-ignore # type: ignore comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants