diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.1fc3af.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.1fc3af.rst new file mode 100644 index 00000000000000..a02631f2da2f9b --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.1fc3af.rst @@ -0,0 +1,2 @@ +Preserve the original :exc:`SyntaxError` if allocating optional error metadata +fails. diff --git a/Parser/pegen.c b/Parser/pegen.c index bb14a1e78c5ad3..9643426fa74c88 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -1083,6 +1083,7 @@ _PyPegen_set_syntax_error_metadata(Parser *p) { ); if (!metadata) { PyErr_Clear(); + PyErr_SetRaisedException(exc); return; } PySyntaxErrorObject *syntax_error = (PySyntaxErrorObject *)exc;