Skip to content
Merged
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