Open
Description
Repro:
def f():
class C:
return
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) or break
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.