From 712dbbbedbb47f7c33cc554ce7b83f3a04e682e6 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 26 Sep 2018 15:46:26 -0700 Subject: [PATCH 1/2] Don't report "function does not return a value" in dynamic functions Fixes a regression introduced in #5663. --- mypy/checkexpr.py | 6 +++++- test-data/unit/check-functions.test | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index ecbb356f7b4d3..0ba58694792e2 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -315,7 +315,11 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) -> self.check_protocol_issubclass(e) if isinstance(ret_type, UninhabitedType) and not ret_type.ambiguous: self.chk.binder.unreachable() - if not allow_none_return and self.always_returns_none(e.callee): + # Warn on calls to functions that always return None. The check + # of ret_type is both a common-case optimization and prevents reporting + # the error in dynamic functions (where it will be Any). + if (not allow_none_return and isinstance(ret_type, NoneTyp) + and self.always_returns_none(e.callee)): self.chk.msg.does_not_return_value(callee_type, e) return AnyType(TypeOfAny.from_error) return ret_type diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 890d0be2dc188..15d7a50d2490e 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2376,3 +2376,11 @@ def Y(x: Optional[str] = X(x_in)): ... xx: Optional[int] = X(x_in) [out] + +[case testNoComplainNoneReturnFromUntyped] +def foo() -> None: + pass + +def lol(): + 1+'uh' + x = foo() From f5ffd97e23e30f28363ffc759736a7065b5aa2ba Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 26 Sep 2018 16:18:37 -0700 Subject: [PATCH 2/2] quick cleanup --- test-data/unit/check-functions.test | 1 - 1 file changed, 1 deletion(-) diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 15d7a50d2490e..876a5fe43f0ce 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2382,5 +2382,4 @@ def foo() -> None: pass def lol(): - 1+'uh' x = foo()