diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-09-27 13:37:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 13:37:43 (GMT) |
commit | e5f13ce5b48b551c09fdd0faeafa6ecf860de51c (patch) | |
tree | d53ec2b8a487a906024e139c106f2a1b21aa810a /Lib/test/test_syntax.py | |
parent | a22be4943c119fecf5433d999227ff78fc2e5741 (diff) | |
download | cpython-e5f13ce5b48b551c09fdd0faeafa6ecf860de51c.zip cpython-e5f13ce5b48b551c09fdd0faeafa6ecf860de51c.tar.gz cpython-e5f13ce5b48b551c09fdd0faeafa6ecf860de51c.tar.bz2 |
bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576)
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r-- | Lib/test/test_syntax.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index aa86d0c..f4a507e 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -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 |