Skip to content

Commit 87ea9ca

Browse files
committed
Added also typing.no_type_check as decorator that disables type checking on a function.
1 parent 3530113 commit 87ea9ca

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ def visit_decorator(self, e: Decorator) -> Type:
16621662

16631663
for d in e.decorators:
16641664
if isinstance(d, NameExpr):
1665-
if d.name == 'no_type_check':
1665+
if d.name == 'no_type_check' or d.name == 'typing.no_type_check':
16661666
return NoneTyp
16671667

16681668
e.func.accept(self)

mypy/parse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ def parse_decorated_function_or_class(self) -> Node:
314314
while self.current_str() == '@':
315315
self.expect('@')
316316
d_exp = self.parse_expression()
317-
if isinstance(d_exp, NameExpr) and d_exp.name == 'no_type_check':
317+
if isinstance(d_exp, NameExpr) and (d_exp.name == 'no_type_check' or
318+
d_exp.name == 'typing.no_type_check'):
318319
no_type_checks = True
319320
decorators.append(d_exp)
320321
self.expect_break()

mypy/test/data/check-functions.test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,11 @@ def f(x, y): pass
561561

562562

563563
[case testDecoratorThatSwitchesTypeWithMethod]
564-
from typing import no_type_checks
564+
from typing import no_type_check
565565

566566
@no_type_check
567567
def foo(x: 'bar', y: {'x': 4}) -> 42:
568568
1 + 'x'
569-
[out]
570-
x
571569

572570

573571
-- Conditional function definition

mypy/test/data/lib-stub/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ def __next__(self) -> T: pass
3535
class Sequence(Generic[T]):
3636
@abstractmethod
3737
def __getitem__(self, n: Any) -> T: pass
38+
39+
def no_type_check(func):
40+
return func

0 commit comments

Comments
 (0)