Skip to content

Commit 25b96b1

Browse files
[3.15] gh-159739: Preserve the syntax error if metadata allocation fails (GH-159751) (#159845)
Restore the original exception when optional syntax-error metadata cannot be allocated. (cherry picked from commit 9c239fb) Co-authored-by: Jelle Zijlstra <jelle@openai.com>
1 parent e99e792 commit 25b96b1

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Preserve the original :exc:`SyntaxError` if allocating optional error metadata
2+
fails.

‎Parser/pegen.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ _PyPegen_set_syntax_error_metadata(Parser *p) {
926926
);
927927
if (!metadata) {
928928
PyErr_Clear();
929+
PyErr_SetRaisedException(exc);
929930
return;
930931
}
931932
PySyntaxErrorObject *syntax_error = (PySyntaxErrorObject *)exc;

0 commit comments

Comments
 (0)