https://github.com/python/cpython/commit/de9deb7ca7120fbb5cbbb53044ce91087065e723
commit: de9deb7ca7120fbb5cbbb53044ce91087065e723
branch: main
author: Victor Stinner <vstin...@python.org>
committer: vstinner <vstin...@python.org>
date: 2025-04-23T08:59:30+02:00
summary:

gh-132713: Simplify list_repr_impl() (#132811)

files:
M Objects/listobject.c

diff --git a/Objects/listobject.c b/Objects/listobject.c
index 3f665a4929f14e..2ac4ce095fcadd 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -595,12 +595,8 @@ list_repr_impl(PyListObject *v)
     /* Do repr() on each element.  Note that this may mutate the list,
        so must refetch the list size on each iteration. */
     for (Py_ssize_t i = 0; i < Py_SIZE(v); ++i) {
-        item = list_get_item_ref(v, i);
-        if (item == NULL) {
-            // List truncated while iterating on it
-            PyErr_Clear();
-            break;
-        }
+        /* Hold a strong reference since repr(item) can mutate the list */
+        item = Py_NewRef(v->ob_item[i]);
 
         if (i > 0) {
             if (PyUnicodeWriter_WriteChar(writer, ',') < 0) {

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to