-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Incorrect "Unused 'type: ignore' comment" on top-level ignore[error-code] #12076
Comments
You have a small typo:
Should be: But the issue is still completely valid. |
Thanks @KotlinIsland, I fixed the code snippet. |
I am not sure if this is a bug or a missing features. The documentation states only to use
(Note that I am not a mypy developer, so I might be wrong) |
It is ignoring the supplied error code, and treating it as though it is just Example showing that it ignores errors with a different code: The documentation currently says:
And on a different page:
The best solution would be to add support for error codes on ignores at the top of a file, to ignore all errors of that code in the whole file. If that isn't possible, I think it should give an error more like (whether used with
|
Put this at the top of the file and you will get the desired behavior: # mypy: allow-untyped-defs playground The following doesn't work (invalid module level config), but is silently ignored due to #12342: # mypy: disable-error-code=no-untyped-def |
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
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
I do not think this handled the solution surgically, it seems to force losing safety for the rule across a *whole file* rather than surgically at the offending line. See also: python/mypy#12076, python/mypy#13512
I do not think this handled the solution surgically, it seems to force losing safety for the rule across a *whole file* rather than surgically at the offending line. See also: python/mypy#12076, python/mypy#13512
Bug Report
When there's a top-level type-ignore with error code, like
# type: ignore[no-untyped-defs]
, and--warn-unused-ignores
is passed, this type comment always shows up as an unused ignore, even though the type checking would fail without that comment.To Reproduce
Create this file:
Run using
mypy test.py --strict
. (which includes--warn-unused-ignores
)Expected Behavior
This should pass, because removing the type comment causes the
no-untyped-def
error to appear.Actual Behavior
Your Environment
Mypy 0.931, Python 3.9.9, Ubuntu 20.04
The text was updated successfully, but these errors were encountered: