Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -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