You can ignore mypy checks on a individual lines as answered here. Is there a way to ignore mypy for a full function?
Is there a way to ignore mypy checks on a single function?
Asked Answered
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? –
Ghent
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). –
Saboteur
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():
...
This doesn't just turn off type checking, but additionally removes any annotations from the function's definition. –
Sarina
@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. –
Lieberman 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) –
Frontlet © 2022 - 2024 — McMap. All rights reserved.