Skip to content

Fix interaction of --warn-no-return and --strict-optional #2371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2016
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