Skip to content

Commit b55984d

Browse files
committed
Reset to previous statement when leaving a return expr in semanal
1 parent 5a78607 commit b55984d

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

mypy/semanal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5332,13 +5332,15 @@ def visit_expression_stmt(self, s: ExpressionStmt) -> None:
53325332
s.expr.accept(self)
53335333

53345334
def visit_return_stmt(self, s: ReturnStmt) -> None:
5335+
old = self.statement
53355336
self.statement = s
53365337
if not self.is_func_scope():
53375338
self.fail('"return" outside function', s)
53385339
if self.return_stmt_inside_except_star_block:
53395340
self.fail('"return" not allowed in except* block', s, serious=True)
53405341
if s.expr:
53415342
s.expr.accept(self)
5343+
self.statement = old
53425344

53435345
def visit_raise_stmt(self, s: RaiseStmt) -> None:
53445346
self.statement = s

test-data/unit/check-classes.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9258,3 +9258,18 @@ main:5: note: def __eq__(self, other: object) -> bool:
92589258
main:5: note: if not isinstance(other, C):
92599259
main:5: note: return NotImplemented
92609260
main:5: note: return <logic to compare two C instances>
9261+
9262+
[case testLambdaInAttributeCallValue]
9263+
# https://github.com/python/mypy/issues/19632
9264+
import foo
9265+
9266+
def nop(fn: object) -> foo.Bar:
9267+
return foo.Bar()
9268+
9269+
class Bar:
9270+
foo: foo.Bar = nop(
9271+
lambda: 0
9272+
)
9273+
[file foo.py]
9274+
class Bar:
9275+
...

0 commit comments

Comments
 (0)