mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #27999: Make "global after use" a SyntaxError, and ditto for nonlocal.
Patch by Ivan Levkivskyi.
This commit is contained in:
parent
95e502e7a6
commit
6cff8744a0
4 changed files with 59 additions and 71 deletions
|
@ -366,7 +366,23 @@ build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514
|
|||
...
|
||||
SyntaxError: too many statically nested blocks
|
||||
|
||||
Misuse of the nonlocal statement can lead to a few unique syntax errors.
|
||||
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
|
||||
|
||||
>>> def f():
|
||||
... x = 1
|
||||
... global x
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: name 'x' is assigned to before global declaration
|
||||
|
||||
>>> def f():
|
||||
... x = 1
|
||||
... def g():
|
||||
... print(x)
|
||||
... nonlocal x
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: name 'x' is used prior to nonlocal declaration
|
||||
|
||||
>>> def f(x):
|
||||
... nonlocal x
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue