https://github.com/python/cpython/commit/4489dc3e16abb09aa2e50a4909ed33f2327ae77d commit: 4489dc3e16abb09aa2e50a4909ed33f2327ae77d branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: encukou <[email protected]> date: 2026-10-13T12:12:05+02:00 summary:
[3.14] gh-156909: Fix `AST.__repr__` call getting the `_fields` attribute (GH-157490) (GH-157596) (GH-159232) (cherry picked from commit ad0a18a17d7f60fab5fdd79d789c53bf3d3c2cd6) Co-authored-by: Bartosz Sławecki <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> files: M Parser/asdl_c.py M Python/Python-ast.c diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index de202aaec8cbbb2..37abdf4b5f3d23b 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -1577,8 +1577,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 2dd2f6778d14749..6ea9bdffed710bb 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -5861,8 +5861,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]
