Return inside class inside function should be an error
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start by reproducing the nested-class example from the issue and inspect the existing handling for return outside a function, including how class scopes are represented. The work is done when this case and the related scope errors are diagnosed consistently without regressing valid returns inside functions.
Written by the indexing model from the issue text.
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.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100