Skip to content

Commit 28cb41d

Browse files
miss-islingtonjelle-openaiJelleZijlstra
authored
[3.14] gh-159739: Preserve the syntax error if metadata allocation fails (GH-159751) (#159846)
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> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 46a54e5 commit 28cb41d

2 files changed

Lines changed: 3 additions & 1 deletion

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ _PyPegen_set_syntax_error_metadata(Parser *p) {
933933
the_source // N gives ownership to metadata
934934
);
935935
if (!metadata) {
936-
Py_DECREF(the_source);
937936
PyErr_Clear();
937+
PyErr_SetRaisedException(exc);
938938
return;
939939
}
940940
PySyntaxErrorObject *syntax_error = (PySyntaxErrorObject *)exc;

0 commit comments

Comments
 (0)