diff --git a/mypy/checker.py b/mypy/checker.py index 206abae6adec..47c72924bf3c 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -5502,7 +5502,7 @@ def visit_with_stmt(self, s: WithStmt) -> None: self.accept(s.body) def check_untyped_after_decorator(self, typ: Type, func: FuncDef) -> None: - if not self.options.disallow_any_decorated or self.is_stub: + if not self.options.disallow_any_decorated or self.is_stub or self.current_node_deferred: return if mypy.checkexpr.has_any_type(typ): diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index bb64bb44d282..8eec979029d0 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -1116,6 +1116,39 @@ def f(x: Any) -> Any: # E: Function is untyped after decorator transformation def h(x): # E: Function is untyped after decorator transformation pass [builtins fixtures/list.pyi] + +[case testDisallowAnyDecoratedUnannotatedDecoratorDeferred1] +# flags: --disallow-any-decorated +from typing import Callable + +def d(f: Callable[[int], None]) -> Callable[[int], None]: + return f + +def wrapper() -> None: + if c: + @d + def h(x): + pass + +c = [1] +[builtins fixtures/list.pyi] + +[case testDisallowAnyDecoratedUnannotatedDecoratorDeferred2] +# flags: --disallow-any-decorated +from typing import Callable + +def d(f: Callable[[int], None]) -> Callable[[int], None]: + return f + +c = 1 # no deferral - check that the previous testcase is valid + +def wrapper() -> None: + if c: + @d + def h(x): + pass +[builtins fixtures/list.pyi] + [case testDisallowAnyDecoratedErrorIsReportedOnlyOnce] # flags: --disallow-any-decorated