You can ignore mypy checks on a individual lines as answered here. Is there a way to ignore mypy for a full function?
Asked
Active
Viewed 1.1k times
23
-
What exactly do you want mypy to ignore? Is the function annotated, but mypy should not use these annotations? Should the *usage* or the *implementation* be ignored, or both? Should the function be checked, but the result ignored? – MisterMiyagi Feb 17 '21 at 10:04
-
Good clarifying question. I found this answer while looking for a solution to the former (I want mypy to be quiet about usage of a particular imported function). – Paul Bissex Dec 12 '22 at 21:26
1 Answers
34
mypy checks can be ignored for a full function by adding @typing.no_type_check
decorator on top of the function.
import typing
@typing.no_type_check
def some_function():
...

Ananda
- 2,925
- 5
- 22
- 45
-
5This doesn't just turn off type checking, but additionally removes any annotations from the function's definition. – BallpointBen Feb 22 '21 at 16:08
-
1`@typing.no_type_check` might be a very big hammer, but it served wonderfully for sidestepping a bug in _mypy_ that caused it to crash on a certain function. – Ben Kovitz Jul 27 '22 at 00:37
-
Strangely this doesn't work in some cases, adding it did silence some errors but not others (eg: `class Foo(bar_module_PrivateClass)` defined inside a function) – Romuald Brunet Jul 28 '23 at 09:18