Skip to content

Add a way to ignore type: ignore, disabled error codes #13201

Description

@copdips

Feature

My goal is to check all the ignored inline mypy errors/warnings

Pitch

People often added inline comment # type: ignore to 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 to flake8 --disable-noqa, which show all the mypy errors/warnings regardless of these inline ignores.

Activity

  1. JelleZijlstra commented on Jul 20, 2022

    @JelleZijlstra
    Member

    There is --warn-unused-ignores, which warns if a type ignore is unused, but there's no option to ignore them completely.

  2. sobolevn commented on Jul 21, 2022

    @sobolevn
    Member

    type: ignore does not just change the error reporting, it also changes types of things. Most of the time type: ignore means that the thing behind it becomes Any.

    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.

  3. erictraut commented on Jul 21, 2022

    @erictraut

    @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.

  4. copdips commented on Jul 21, 2022

    @copdips
    Author

    @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.

  5. JukkaL commented on Jul 21, 2022

    @JukkaL
    Collaborator

    @erictraut is correct, a #type: ignore comment 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: ignore with # xtype: ignore, and run mypy normally.

  6. changed the title [-]Does mypy have similar thing to `flake8 --disable-noqa`[/-] [+]Add a way to ignore `type: ignore`[/+] on Aug 3, 2022
  7. changed the title [-]Add a way to ignore `type: ignore`[/-] [+]Add a way to ignore `type: ignore`, disabled error codes[/+] on Aug 3, 2022
  8. ssbarnea commented on May 21, 2023

    @ssbarnea
    SponsorContributor

    I am in a conundrum because the Unused "type: ignore" comment error 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.

  9. hauntsaninja commented on May 21, 2023

    @hauntsaninja
    Collaborator

    @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__ or cast or if not TYPE_CHECKING (see some of the examples in #8823)

  10. jvanasco commented on Jul 17, 2025

    @jvanasco

    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.

  11. wyattscarpenter commented on Jul 23, 2025

    @wyattscarpenter
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions