Skip to content

Commit

Permalink
Avoid does not return error in lambda (python#17294)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored May 28, 2024
1 parent 5059ffd commit f60f458
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
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

0 comments on commit f60f458

Please sign in to comment.