Skip to content

Fix accidentally disallowing empty returns in strict-optional #1981

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
Aug 3, 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
5 changes: 1 addition & 4 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -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