diff --git a/mypy/checker.py b/mypy/checker.py index 11158109ab44..d631c8f0a11e 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -2133,7 +2133,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None: if isinstance(typ, AnyType): # (Unless you asked to be warned in that case, and the # function is not declared to return Any) - if (self.options.warn_return_any and + if (self.options.warn_return_any and not self.current_node_deferred and not is_proper_subtype(AnyType(TypeOfAny.special_form), return_type)): self.msg.incorrectly_returning_any(return_type, s) return diff --git a/test-data/unit/check-warnings.test b/test-data/unit/check-warnings.test index ef2f68386917..4acbfe69df80 100644 --- a/test-data/unit/check-warnings.test +++ b/test-data/unit/check-warnings.test @@ -197,3 +197,15 @@ class Test(object): return None [builtins fixtures/list.pyi] [out] + +[case testReturnAnyDeferred] +# flags: --warn-return-any +def foo(a1: A) -> int: + if a1._x: + return 1 + n = 1 + return n + +class A: + def __init__(self, x: int) -> None: + self._x = x