gh-135422: Fix regression in SyntaxError messages after #134036 (#135423)

This commit is contained in:
sobolevn 2025-06-30 21:52:26 +03:00 committed by GitHub
parent fc82cb91ba
commit 7e33558455
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 2509 additions and 2505 deletions

View file

@ -184,8 +184,9 @@ return_stmt[stmt_ty]:
| 'return' a=[star_expressions] { _PyAST_Return(a, EXTRA) }
raise_stmt[stmt_ty]:
| 'raise' a=expression 'from' b=expression { _PyAST_Raise(a, b, EXTRA) }
| invalid_raise_stmt
| 'raise' a=expression b=['from' z=expression { z }] { _PyAST_Raise(a, b, EXTRA) }
| 'raise' a=expression { _PyAST_Raise(a, NULL, EXTRA) }
| 'raise' { _PyAST_Raise(NULL, NULL, EXTRA) }
pass_stmt[stmt_ty]:

View file

@ -2872,6 +2872,13 @@ class SyntaxErrorTestCase(unittest.TestCase):
"""
self._check_error(source, "parameter and nonlocal", lineno=3)
def test_raise_from_error_message(self):
source = """if 1:
raise AssertionError() from None
print(1,,2)
"""
self._check_error(source, "invalid syntax", lineno=3)
def test_yield_outside_function(self):
self._check_error("if 0: yield", "outside function")
self._check_error("if 0: yield\nelse: x=1", "outside function")

View file

@ -0,0 +1 @@
Fix regression in :exc:`SyntaxError` messages after :gh:`134036`.

5003
Parser/parser.c generated

File diff suppressed because it is too large Load diff