python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.55k stars 2.84k forks source link

Allow to ignore type errors per line specifically for mypy #18134

Closed mar10 closed 2 weeks ago

mar10 commented 2 weeks ago

Feature

Allow to ignore type errors specifically for mypy, in a way that will not interfere with other type checkers.

Suggestion:

val: str = None  # mypy: ignore 

Note that the example above would correctly report an error. It should just show the proposed syntax. See #18133 for a real-word example.

Pitch

mypy, like any other library, may have bugs, or report warnings that we deliberately want to ignore.

This page suggests

If your code uses any of the above unsupported features and is causing errors when mypy checks your code, you can bypass it by adding # type: ignore to the line that causes the error.

This however is not an option if other type checkers, such as pyright do not report an error. For example if pyright correctly accepts a line, it will correctly report an error Unnecessary "# type: ignore" comment

hamdanal commented 2 weeks ago

Duplicate of #12358