https://github.com/python/cpython/commit/ad0a18a17d7f60fab5fdd79d789c53bf3d3c2cd6
commit: ad0a18a17d7f60fab5fdd79d789c53bf3d3c2cd6
branch: 3.15
author: Bartosz SÅ‚awecki <[email protected]>
committer: encukou <[email protected]>
date: 2026-10-12T14:08:25+02:00
summary:

[3.15] gh-156909: Fix `AST.__repr__` call getting the `_fields` attribute 
(GH-157490) (GH-157596)

(cherry picked from commit 1bfcc3cc871d3fab21b77cdc47cdbfcf89fd8b5b)

files:
M Parser/asdl_c.py
M Python/Python-ast.c

diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 5d321f96f92162c..c381d2ea4849d6a 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -1480,8 +1480,8 @@ def visitModule(self, mod):
         return PyUnicode_FromFormat("%s(...)", Py_TYPE(self)->tp_name);
     }
 
-    PyObject *fields;
-    if (PyObject_GetOptionalAttr((PyObject *)Py_TYPE(self), state->_fields, 
&fields) < 0) {
+    PyObject *fields = PyObject_GetAttr((PyObject *)Py_TYPE(self), 
state->_fields);
+    if (!fields) {
         Py_ReprLeave((PyObject *)self);
         return NULL;
     }
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 63b0215ebe2c0a1..c7ac3294b595fd5 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -5805,8 +5805,8 @@ ast_repr_max_depth(AST_object *self, int depth)
         return PyUnicode_FromFormat("%s(...)", Py_TYPE(self)->tp_name);
     }
 
-    PyObject *fields;
-    if (PyObject_GetOptionalAttr((PyObject *)Py_TYPE(self), state->_fields, 
&fields) < 0) {
+    PyObject *fields = PyObject_GetAttr((PyObject *)Py_TYPE(self), 
state->_fields);
+    if (!fields) {
         Py_ReprLeave((PyObject *)self);
         return NULL;
     }

_______________________________________________
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