summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorIvan Levkivskyi <levkivskyi@gmail.com>2017-10-26 21:28:35 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-26 21:28:35 (GMT)
commit8c83c23fa32405aa9212f028d234f4129d105a23 (patch)
tree17bffa5e67b52870e4d3e4db2c20ebcb320f5a4e /Lib/test
parent66c88ce30ca2b23daa37038e1a3c0de98f241f50 (diff)
downloadcpython-8c83c23fa32405aa9212f028d234f4129d105a23.zip
cpython-8c83c23fa32405aa9212f028d234f4129d105a23.tar.gz
cpython-8c83c23fa32405aa9212f028d234f4129d105a23.tar.bz2
bpo-28936: Detect lexically first syntax error first (#4097)
Lexically first global and nonlocal syntax errors at given scope should be detected first.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_syntax.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 7ce3d75..5d36581 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -400,12 +400,25 @@ build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
>>> def f():
+ ... print(x)
+ ... global x
+ Traceback (most recent call last):
+ ...
+ SyntaxError: name 'x' is used prior to global declaration
+
+ >>> def f():
... x = 1
... global x
Traceback (most recent call last):
...
SyntaxError: name 'x' is assigned to before global declaration
+ >>> def f(x):
+ ... global x
+ Traceback (most recent call last):
+ ...
+ SyntaxError: name 'x' is parameter and global
+
>>> def f():
... x = 1
... def g():
@@ -560,7 +573,6 @@ Corner-cases that used to crash:
import re
import unittest
-import warnings
from test import support
@@ -596,19 +608,25 @@ class SyntaxTestCase(unittest.TestCase):
def test_assign_del(self):
self._check_error("del f()", "delete")
- def test_global_err_then_warn(self):
- # Bug #763201: The SyntaxError raised for one global statement
- # shouldn't be clobbered by a SyntaxWarning issued for a later one.
+ def test_global_param_err_first(self):
source = """if 1:
def error(a):
global a # SyntaxError
- def warning():
+ def error2():
+ b = 1
+ global b # SyntaxError
+ """
+ self._check_error(source, "parameter and global", lineno=3)
+
+ def test_nonlocal_param_err_first(self):
+ source = """if 1:
+ def error(a):
+ nonlocal a # SyntaxError
+ def error2():
b = 1
- global b # SyntaxWarning
+ global b # SyntaxError
"""
- warnings.filterwarnings(action='ignore', category=SyntaxWarning)
- self._check_error(source, "global")
- warnings.filters.pop(0)
+ self._check_error(source, "parameter and nonlocal", lineno=3)
def test_break_outside_loop(self):
self._check_error("break", "outside loop")