From 40a453a3bbd6c4ebe12f588f744ac8a13abbd8b5 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Thu, 30 Nov 2017 10:12:30 +0200 Subject: [PATCH 1/2] do not warn on returning any from deferred node --- mypy/checker.py | 2 +- test-data/unit/check-warnings.test | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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..5a177aa9c953 100644 --- a/test-data/unit/check-warnings.test +++ b/test-data/unit/check-warnings.test @@ -197,3 +197,17 @@ 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 + + From 69a678b07c3f301077c34cccce3b72e4b730082f Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Thu, 30 Nov 2017 12:47:06 +0200 Subject: [PATCH 2/2] Remove empty lines --- test-data/unit/check-warnings.test | 2 -- 1 file changed, 2 deletions(-) diff --git a/test-data/unit/check-warnings.test b/test-data/unit/check-warnings.test index 5a177aa9c953..4acbfe69df80 100644 --- a/test-data/unit/check-warnings.test +++ b/test-data/unit/check-warnings.test @@ -209,5 +209,3 @@ def foo(a1: A) -> int: class A: def __init__(self, x: int) -> None: self._x = x - -