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

Avoid does not return error in lambda #17294

Merged
merged 1 commit into from
May 28, 2024
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 @@ -4494,7 +4494,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
is_lambda = isinstance(self.scope.top_function(), LambdaExpr)
if isinstance(return_type, UninhabitedType):
# Avoid extra error messages for failed inference in lambdas
if not is_lambda or not return_type.ambiguous:
if not is_lambda and not return_type.ambiguous:
self.fail(message_registry.NO_RETURN_EXPECTED, s)
return

Expand Down
11 changes: 2 additions & 9 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -1502,15 +1502,8 @@ from typing import Callable, NoReturn
def foo() -> NoReturn:
raise

f = lambda: foo()
f1 = lambda: foo()
x = 0 # not unreachable

[case testLambdaNoReturnAnnotated]
# flags: --warn-unreachable
from typing import Callable, NoReturn

def foo() -> NoReturn:
raise

f: Callable[[], NoReturn] = lambda: foo() # E: Return statement in function which does not return # (false positive: https://github.com/python/mypy/issues/17254)
f2: Callable[[], NoReturn] = lambda: foo()
x = 0 # not unreachable
Loading