You can ignore mypy checks on a individual lines as answered here. Is there a way to ignore mypy for a full function?
-
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?– user5349916Commented Feb 17, 2021 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 BissexCommented Dec 12, 2022 at 21:26
Add a comment
|
1 Answer
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():
...
-
6This doesn't just turn off type checking, but additionally removes any annotations from the function's definition. Commented Feb 22, 2021 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. Commented Jul 27, 2022 at 0: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) Commented Jul 28, 2023 at 9:18