-
-
Notifications
You must be signed in to change notification settings - Fork 3k
1.16 regression: --warn-unused-ignore
now complains in ignored-but-correct places
#19237
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
Comments
this seems intentional via #11059 and #18849 (bisected to 6b68661) I'd still argue this is worse than before for my use case and I'm not quite sure what the motivation was in the original issue -- cc @Akuli @brianschubert |
actually I do see it in the notes now -- I was searching for the wrong thing ( |
Yeah, this was an intentional change. The ignore is unused in the sense it isn't necessary under the current configuration and removing it would not result in a diagnostic being emitted. This is generally a useful behavior, since it lets you detect As a workaround, you can try disabling the def f() -> None:
x: int = 'hi' # type: ignore[assignment,unused-ignore] I'll note that the previous behavior was buggy in that only some errors could be both ignored and disabled without setting off Also FWIW, the current behavior is consistent with how other static analysis tools I've used work. For example, ruff's RUF100 rule handles unused ruff unused noqa behavior$ cat t1.py
def f() -> None:
x: int = 'hi'
$ ruff check --select=F,RUF t1.py
t1.py:2:5: F841 Local variable `x` is assigned to but never used
|
1 | def f() -> None:
2 | x: int = 'hi'
| ^ F841
|
= help: Remove assignment to unused variable `x`
# Add '# noqa' comment
$ cat t2.py
def f() -> None:
x: int = 'hi' # noqa: F841
# Linting now passes
$ ruff check --select=F,RUF t2.py
All checks passed!
# Now disable the rule with '--ignore=F841'
# Ruff now warns you about the unused '# noqa' comment
$ ruff check --select=F,RUF --ignore=F841 t2.py
t2.py:2:20: RUF100 [*] Unused `noqa` directive (non-enabled: `F841`)
|
1 | def f() -> None:
2 | x: int = 'hi' # noqa: F841
| ^^^^^^^^^^^^ RUF100
|
= help: Remove unused `noqa` directive
Found 1 error.
[*] 1 fixable with the `--fix` option. |
tagging with I don't think ruff's behaviour is particularly relevant -- incremental application isn't a common approach there. |
@asottile-sentry how does adding |
again that defeats the whole point for me |
But then the type-ignores won't live forever, only until you remove the pair of configurations from your configuration file. |
it won't but it lets other completely wrong type ignores creep in / stick around |
I see, that's true. |
Besides the obvious solutions (the one I just mentioned, the one brianschubert mentioned, changing the behavior of warn-unused-ignores back, introducing a new configuration warn_unused_ignores_except, & just removing the type ignores), which all have their drawbacks, you could also check out basedmypy's baselining feature https://kotlinisland.github.io/basedmypy/baseline. Basedmypy is a fork of mypy and has slightly different behavior sometimes (and different things enabled by default), but there's a slight chance that it's exactly what you need. |
yeah I'm never using anything by that author or with "based" in the name so that's not really a fix to mypy's behaviour change |
this appears to have changed behaviour in mypy 1.15 -- I personally prefer the behaviour in 1.15 but would understand if it needed to change. I don't see it mentioned in the changelog however
Bug Report
we're working on incrementally typing a large codebase -- often this means fixing a particular callsite or file at a time (sometimes by intentionally ignoring errors unfortunately)
it seems that in a module with a particular error code (temporarily) disabled,
--warn-unused-ignores
will complain about a "correct" type ignore (I say "correct" here as it will complain when the file is no longer blocklisted) -- will provide a small example belowTo Reproduce
Expected Behavior
Actual Behavior
Your Environment
mypy.ini
(and other config files): (see above)The text was updated successfully, but these errors were encountered: