bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576)

(cherry picked from commit e5f13ce5b4)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-09-27 07:05:20 -07:00 committed by GitHub
parent fae2694bea
commit 9e209d48ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 8 deletions

View file

@ -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