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>
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 @@
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 @@ def _check_error(self, code, errtext,
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 @@ def test_kwargs_last3(self):
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