diff --git a/mypy/checker.py b/mypy/checker.py index 4d8221415754..73565f990dd9 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -5433,7 +5433,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..c995b2d7eb33 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -1116,6 +1116,38 @@ 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 + +def d(f): + return f + +def wrapper() -> None: + if c: + @d + def h(x): # E: Function is untyped after decorator transformation + pass + +c = [1] +[builtins fixtures/list.pyi] + +[case testDisallowAnyDecoratedUnannotatedDecoratorDeferred2] +# flags: --disallow-any-decorated + +def d(f): + return f + +c = 1 # no deferral - check that the previous testcase is valid + +def wrapper() -> None: + if c: + @d + def h(x): # E: Function is untyped after decorator transformation + pass + +[builtins fixtures/list.pyi] + [case testDisallowAnyDecoratedErrorIsReportedOnlyOnce] # flags: --disallow-any-decorated