Return inside class inside function should be an error #1683
Labels
bug
mypy got something wrong
priority-2-low
topic-runtime-semantics
mypy doesn't model runtime semantics correctly
Repro:
That's invalid Python, but mypy doesn't flag it as an error. The new parser doesn't diagnose this either, since this is a "syntax error" that's reported by a later pass, after the full AST has been constructed. There are a few others like this, e.g.
return
outside function (which is flagged) orbreak
outside loop.I discovered this when reading some mypy code -- the code that complains about
return
outside a function doesn't realize that the stack of scopes may contain a class. I suspect this is easy to fix, but I'm not sure so I'm not labeling it as such just yet.UPDATE: I should add this is very low priority, since this is obviously an error that Python itself reports reliably.
The text was updated successfully, but these errors were encountered: