From 8f2ffb8c5b481cd5f96caaf7fbba95ea0cbd7a5f Mon Sep 17 00:00:00 2001 From: David Fisher Date: Fri, 28 Oct 2016 11:23:52 -0700 Subject: [PATCH] Fix interaction of --warn-no-return and --strict-optional --- mypy/checker.py | 2 +- test-data/unit/check-optional.test | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mypy/checker.py b/mypy/checker.py index 8244fffa21cfa..acb1c4742df01 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -634,7 +634,7 @@ def is_implicit_any(t: Type) -> bool: unreachable = self.binder.is_unreachable() if (self.options.warn_no_return and not unreachable - and not isinstance(self.return_types[-1], (Void, AnyType)) + and not isinstance(self.return_types[-1], (Void, NoneTyp, AnyType)) and not defn.is_generator): # Control flow fell off the end of a function that was # declared to return a non-None type. diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index a477de3b3510e..d33c4c8442ee5 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -497,3 +497,15 @@ if x == y: else: reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.int, builtins.None]' [builtins fixtures/ops.pyi] + + +[case testWarnNoReturnWorksWithStrictOptional] +# flags: --warn-no-return +def f() -> None: + 1 + 1 # no error + +def g() -> int: + 1 + 1 # +[out] +main: note: In function "g": +main:5: note: Missing return statement