https://github.com/python/cpython/commit/28cb41d4600bee63fd721b6957cb50cc392d81de
commit: 28cb41d4600bee63fd721b6957cb50cc392d81de
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-20T18:37:34Z
summary:

[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 9c239fb50a7f2821359ed3dc82993fba7da7d41c)

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.1fc3af.rst
M Parser/pegen.c

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 000000000000000..a02631f2da2f9b2
--- /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 1dc039fccfa2491..fb8d7977ec0427b 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -933,8 +933,8 @@ _PyPegen_set_syntax_error_metadata(Parser *p) {
         the_source // N gives ownership to metadata
     );
     if (!metadata) {
-        Py_DECREF(the_source);
         PyErr_Clear();
+        PyErr_SetRaisedException(exc);
         return;
     }
     PySyntaxErrorObject *syntax_error = (PySyntaxErrorObject *)exc;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to