Skip to content
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: 2 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5332,13 +5332,15 @@ def visit_expression_stmt(self, s: ExpressionStmt) -> None:
s.expr.accept(self)

def visit_return_stmt(self, s: ReturnStmt) -> None:
old = self.statement
self.statement = s
if not self.is_func_scope():
self.fail('"return" outside function', s)
if self.return_stmt_inside_except_star_block:
self.fail('"return" not allowed in except* block', s, serious=True)
if s.expr:
s.expr.accept(self)
self.statement = old

def visit_raise_stmt(self, s: RaiseStmt) -> None:
self.statement = s
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -9258,3 +9258,18 @@ main:5: note: def __eq__(self, other: object) -> bool:
main:5: note: if not isinstance(other, C):
main:5: note: return NotImplemented
main:5: note: return <logic to compare two C instances>

[case testLambdaInAttributeCallValue]
# https://github.com/python/mypy/issues/19632
import foo

def nop(fn: object) -> foo.Bar:
return foo.Bar()

class Bar:
foo: foo.Bar = nop(
lambda: 0
)
[file foo.py]
class Bar:
...
Loading