mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576)
This commit is contained in:
parent
a22be4943c
commit
e5f13ce5b4
5 changed files with 31 additions and 8 deletions
|
@ -1274,7 +1274,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
|
||||
|
@ -1294,6 +1295,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")
|
||||
|
||||
|
@ -1433,6 +1439,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue