diff --git a/mypy/checker.py b/mypy/checker.py index b56ef2c9ccea..d959f73b8212 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -1453,10 +1453,7 @@ def visit_return_stmt(self, s: ReturnStmt) -> Type: if (self.function_stack[-1].is_generator and isinstance(return_type, AnyType)): return None - if isinstance(return_type, Void): - return None - - if isinstance(return_type, AnyType): + if isinstance(return_type, (Void, NoneTyp, AnyType)): return None if self.typing_mode_full(): diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index 0367116224fe..d136874157b3 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -298,3 +298,11 @@ def g(x: Optional[int]) -> int: x = f() # E: Function does not return a value f() + 1 # E: Function does not return a value g(f()) # E: Function does not return a value + +[case testEmptyReturn] +def f() -> None: + return + +[case testReturnNone] +def f() -> None: + return None