Skip to content
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

Allow Void typed values as returns from None functions #2829

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,8 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
if self.is_unusable_type(return_type):
# Lambdas are allowed to have a unusable returns.
# Functions returning a value of type None are allowed to have a Void return.
if isinstance(self.scope.top_function(), FuncExpr) or isinstance(typ, NoneTyp):
if isinstance(self.scope.top_function(), FuncExpr) or \
isinstance(typ, (NoneTyp, Void)):
return
self.fail(messages.NO_RETURN_VALUE_EXPECTED, s)
else:
Expand Down
8 changes: 0 additions & 8 deletions test-data/unit/check-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ class A:
[out]
main:3: error: Return value expected

[case testReturnNoneInFunctionReturningNone]
import typing
def f() -> None:
return None
def g() -> None:
return f() # E: No return value expected
[out]

[case testReturnInGenerator]
from typing import Generator
def f() -> Generator[int, None, str]:
Expand Down