summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2016-09-09 16:36:26 (GMT)
committerGuido van Rossum <guido@dropbox.com>2016-09-09 16:36:26 (GMT)
commit6cff8744a0ae58c88728df8bbca4580ffa6c6a86 (patch)
tree8cd1a3c28fdc74e6f432661661f306e9feb2bc6d /Lib/test/test_syntax.py
parent95e502e7a664c588bcd9d895af285a32ce8246fe (diff)
downloadcpython-6cff8744a0ae58c88728df8bbca4580ffa6c6a86.zip
cpython-6cff8744a0ae58c88728df8bbca4580ffa6c6a86.tar.gz
cpython-6cff8744a0ae58c88728df8bbca4580ffa6c6a86.tar.bz2
Issue #27999: Make "global after use" a SyntaxError, and ditto for nonlocal.
Patch by Ivan Levkivskyi.
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index f47bdf9..80e36fd 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -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