From bd224d8e28f387000886b41af5ab6ae5758f9c9a Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 25 May 2024 22:20:54 -0700 Subject: [PATCH] Avoid does not return error in lambda --- mypy/checker.py | 2 +- test-data/unit/check-unreachable-code.test | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 72bbc3d284ef..179ff6e0b4b6 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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 diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index 81777f4c0e2b..cbad1bd5449e 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -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