Repository navigation
Add a way to ignore type: ignore, disabled error codes #13201
Description
Activity
There is
--warn-unused-ignores, which warns if a type ignore is unused, but there's no option to ignore them completely.type: ignoredoes not just change the error reporting, it also changes types of things. Most of the timetype: ignoremeans that the thing behind it becomesAny.And all parts of code matter for mypy (unlike flake8).
So, I don't think we need such a flag: un-silencing errors in this case can bring very confusing results.
@sobolevn, what do you mean that "it also changes types of things"? My understanding is that mypy simply suppresses any errors on a line with a
# type: ignore, and that the comment has no other effect in terms of type checking.FWIW, pyright has an option that does what @copdips is requesting here (`"enableTypeIgnoreComments": false) to accommodate this use case.
Reacted by Jasha Sommer-Simpson and Xiang ZHU@erictraut,
Thx for your trick with vscode, but in fact, I need the option during CICD time.
For e.g. with flake8, I run two commands:flake8 flake8 --disable-noqa --exit-zero
The first one is for the real CI check, and the second one is just for the review/audit.
That's why I asked if we have similar thing in mypy.@erictraut is correct, a
#type: ignorecomment should only suppress errors on the line, so the proposed feature is a reasonable one.If you know which code is type checked by mypy, it's easy enough to use some grep-like tool to find type ignores, for example something like this:
$ rg '# *type: *ignore\b'This doesn't show the errors that are ignored, however.
As a quick hack, you could use sed to temporarily replace, say,
# type: ignorewith# xtype: ignore, and run mypy normally.Reacted by Xiang ZHU and Shantanu- changed the title
[-]Does mypy have similar thing to `flake8 --disable-noqa`[/-][+]Add a way to ignore `type: ignore`[/+]on Aug 3, 2022 - changed the title
[-]Add a way to ignore `type: ignore`[/-][+]Add a way to ignore `type: ignore`, disabled error codes[/+]on Aug 3, 2022 I am in a conundrum because the
Unused "type: ignore" commenterror seems impossible to ignore in a specific location.I do have a file that might be missing:
try: from ._version import version as __version__ # type: ignore except ImportError: # pragma: no cover __version__ = "0.1.dev1"
Once mypy is configured to detect unused ignores (useful feature), I cannot make it really ignore this line. Keep in mind that there are two cases here, one where the file exists and one where the file does not exist.
I want to ensure mypy does not annoy me about this particular line only.
@ssbarnea your issue is unrelated to the feature request here, I think it's more related to #15164 which should fix your kind of thing (will be included in next release). In particular, see this test case . For now, you can likely hack around it using
__import__orcastorif not TYPE_CHECKING(see some of the examples in #8823)- addedtopic-configurationConfiguration files and flagsConfiguration files and flagstopic-type-ignore# type: ignore comments# type: ignore comments
on Jul 17, 2025 - marked runtime flag to disable all
# type: ignorecomments #19476 as a duplicate of this issueon Jul 17, 2025 While this is possible to accomplish by stripping out the lines or renaming them, that just means it is possible for those that are seeking out this functionality. IMHO, periodic audits like this should be a standard practice for managing projects over time - and that's not going to happen without first-party support. Along with general Python typing improvements, MyPy's errors and suggestions are constantly improving – projects often miss updating to now-easy typing support (or better idioms) because of legacy ignores.
This would probably be a pretty easy change for an enterprising individual to effect. Possibly a "good second issue". You basically just need to add a flag, an if statement checking that flag at the appropriate place, tests, and documentation.
My recent PR https://github.com/python/mypy/pull/19048/files isn't the cleanest, but it touches several of the same parts of the codebase, and could serve as a guide if any novice mypy-contributor were interested in taking up this channel.
- added a commit that references this issue
on Sep 27, 2025
Feature
My goal is to check all the ignored
inlinemypy errors/warningsPitch
People often added inline comment
# type: ignoreto ignore mypy error for a specific line, but it's difficult to trace for other developers, or for audit purpose. Now I would like to have something similar toflake8 --disable-noqa, which show all the mypy errors/warnings regardless of these inline ignores.