summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-09-27 14:05:20 (GMT)
committerGitHub <noreply@github.com>2021-09-27 14:05:20 (GMT)
commit9e209d48cac35108f3955d3f610b6ce60b574ecc (patch)
tree20449bd0d874070874768121fd832a4e7cafac0d /Lib/test/test_syntax.py
parentfae2694bea5e9e5a114af8cb40b60e7131a6340c (diff)
downloadcpython-9e209d48cac35108f3955d3f610b6ce60b574ecc.zip
cpython-9e209d48cac35108f3955d3f610b6ce60b574ecc.tar.gz
cpython-9e209d48cac35108f3955d3f610b6ce60b574ecc.tar.bz2
bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576)
(cherry picked from commit e5f13ce5b48b551c09fdd0faeafa6ecf860de51c) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index be8be89..f9deb7b 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -1273,7 +1273,8 @@ from test import support
class SyntaxTestCase(unittest.TestCase):
def _check_error(self, code, errtext,
- filename="<testcase>", mode="exec", subclass=None, lineno=None, offset=None):
+ filename="<testcase>", mode="exec", subclass=None,
+ lineno=None, offset=None, end_lineno=None, end_offset=None):
"""Check that compiling code raises SyntaxError with errtext.
errtest is a regular expression that must be present in the
@@ -1293,6 +1294,11 @@ class SyntaxTestCase(unittest.TestCase):
self.assertEqual(err.lineno, lineno)
if offset is not None:
self.assertEqual(err.offset, offset)
+ if end_lineno is not None:
+ self.assertEqual(err.end_lineno, end_lineno)
+ if end_offset is not None:
+ self.assertEqual(err.end_offset, end_offset)
+
else:
self.fail("compile() did not raise SyntaxError")
@@ -1432,6 +1438,11 @@ class SyntaxTestCase(unittest.TestCase):
self._check_error("int(**{'base': 10}, *['2'])",
"iterable argument unpacking follows "
"keyword argument unpacking")
+
+ def test_generator_in_function_call(self):
+ self._check_error("foo(x, y for y in range(3) for z in range(2) if z , p)",
+ "Generator expression must be parenthesized",
+ lineno=1, end_lineno=1, offset=11, end_offset=53)
def test_empty_line_after_linecont(self):
# See issue-40847