Skip to content

Commit de9deb7

Browse files
authored
gh-132713: Simplify list_repr_impl() (#132811)
1 parent 77605fa commit de9deb7

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

Objects/listobject.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,8 @@ list_repr_impl(PyListObject *v)
595595
/* Do repr() on each element. Note that this may mutate the list,
596596
so must refetch the list size on each iteration. */
597597
for (Py_ssize_t i = 0; i < Py_SIZE(v); ++i) {
598-
item = list_get_item_ref(v, i);
599-
if (item == NULL) {
600-
// List truncated while iterating on it
601-
PyErr_Clear();
602-
break;
603-
}
598+
/* Hold a strong reference since repr(item) can mutate the list */
599+
item = Py_NewRef(v->ob_item[i]);
604600

605601
if (i > 0) {
606602
if (PyUnicodeWriter_WriteChar(writer, ',') < 0) {

0 commit comments

Comments
 (0)