Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,13 @@ def error2():
"""
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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression in :exc:`SyntaxError` messages after :gh:`134036`.
Loading
Loading