python / python/mypy

Support `mypy: ignore` inline comments to suppress mypy errors

Open
#12,358 21 comments 53 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-type-ignore
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

Mypy should allow using inline mypy: ignore comments, treating them exactly the same as the equivalent type: ignore comment.

Pitch

Currently, mypy supports type: ignore comments for suppressing errors only on a given line. These are an essential tool for users hitting a bug in mypy to work around the bug.

However, type: ignore comments affect other type checkers as well. When a bug in mypy is causing it to flag a line that other type checkers are not flagging, the user can't add a type: ignore to that line without causing their other type checkers to complain about an unused ignore.

If users could add a mypy: ignore comment instead, this would not affect other type checkers, and would make it self-evident that the line is only being flagged by mypy, and not other type checkers in use.

Furthermore, since other type checkers now support similar comments just for them (e.g. Pyright now supports pyright: ignore comments), if this feature were implemented for mypy, users using multiple type checkers would have a clearer way of indicating what's going on on a given line:

  1. type: ignore: All type checkers agree there's an error here
  2. mypy: ignore: Only mypy thinks this is an error (false positive in mypy or false negative in others)
  3. pyright: ignore: Only pyright thinks this is an error (false positive in pyright or false negative in others)
    etc.

In summary, this feature would make it easier for users to use mypy with other type checkers on the same codebase, to discover new type checker bugs when they disagree (I've already found and reported several this way myself), and could ultimately lead to type checkers becoming less buggy more quickly and agreeing with one another more often.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating mypy's handling of inline type: ignore comments and the tests covering their behavior. Add equivalent support for mypy: ignore, ensuring it suppresses only mypy errors, then verify that existing type: ignore behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.