Skip to content

Commit b9147fe

Browse files
authored
Always respect @no_type_check in two-phase checking (#21320)
This is a somewhat weird, but surprisingly popular edge case.
1 parent cf845c1 commit b9147fe

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

mypy/checker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ def check_partial_impl(self, impl: FuncDef | Decorator) -> None:
701701
if isinstance(impl, FuncDef):
702702
self.visit_func_def_impl(impl)
703703
else:
704+
if any(refers_to_fullname(d, "typing.no_type_check") for d in impl.decorators):
705+
return
704706
with self.tscope.function_scope(impl.func):
705707
self.check_func_item(impl.func, name=impl.func.name)
706708

@@ -5689,12 +5691,10 @@ def visit_del_stmt(self, s: DelStmt) -> None:
56895691
)
56905692

56915693
def visit_decorator(self, e: Decorator) -> None:
5692-
for d in e.decorators:
5693-
if isinstance(d, RefExpr):
5694-
if d.fullname == "typing.no_type_check":
5695-
e.var.type = AnyType(TypeOfAny.special_form)
5696-
e.var.is_ready = True
5697-
return
5694+
if any(refers_to_fullname(d, "typing.no_type_check") for d in e.decorators):
5695+
e.var.type = AnyType(TypeOfAny.special_form)
5696+
e.var.is_ready = True
5697+
return
56985698
self.visit_decorator_inner(e)
56995699

57005700
def visit_decorator_inner(

test-data/unit/check-functions.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,14 @@ def foo(x: {1:2}) -> [1]:
10221022
x = y
10231023
[typing fixtures/typing-medium.pyi]
10241024

1025+
[case testNoTypeCheckDecoratorNoUntypedDefs]
1026+
# flags: --disallow-untyped-defs
1027+
import typing
1028+
1029+
@typing.no_type_check
1030+
def foo(x: "foo") -> "bar":
1031+
x: "whatever"
1032+
[typing fixtures/typing-medium.pyi]
10251033

10261034
-- Forward references to decorated functions
10271035
-- -----------------------------------------

0 commit comments

Comments
 (0)