Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Closed
Description
Bug report
Bug description:
I think theglobal a
has no prior use in this code (and pyright tells me the same). But I don't understand why cpython thinks it has a prior use.
a=5deff():try:passexcept:globalaelse:print(a)
output (Python 3.12.0):
File"/home/frank/projects/pysource-playground/pysource-codegen/bug.py",line8globala^^^^^^^^SyntaxError:name'a'isusedpriortoglobaldeclaration
the following code has no syntax error:
a=5deff():try:passexcept:globalaprint(a)
I can also reproduce this issue in 3.7.
I also don't know what the exact semantic of global/nonlocal inside statements like if/while/try/... is. I would like to know more about it because I'm currently writingpysource-codegen where I generate such cases.
CPython versions tested on:
3.12
Operating systems tested on:
Linux