Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return inside class inside function should be an error #1683

Open
gvanrossum opened this issue Jun 9, 2016 · 0 comments
Open

Return inside class inside function should be an error #1683

gvanrossum opened this issue Jun 9, 2016 · 0 comments
Labels
bug mypy got something wrong priority-2-low topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@gvanrossum
Copy link
Member

gvanrossum commented Jun 9, 2016

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.

@gvanrossum gvanrossum added the bug mypy got something wrong label Jun 9, 2016
@AlexWaygood AlexWaygood added the topic-runtime-semantics mypy doesn't model runtime semantics correctly label Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

3 participants