https://github.com/python/cpython/commit/12fbc90e063b118f489241ae9f806a9d694a5682
commit: 12fbc90e063b118f489241ae9f806a9d694a5682
branch: main
author: Ilya Egorov <[email protected]>
committer: corona10 <[email protected]>
date: 2026-10-08T08:56:38+09:00
summary:

gh-158592: Reallocate the list's array when deleting by index (gh-158602)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-10-02-16-19-35.gh-issue-158592.V6W21J.rst
M Objects/listobject.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-02-16-19-35.gh-issue-158592.V6W21J.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-02-16-19-35.gh-issue-158592.V6W21J.rst
new file mode 100644
index 00000000000000..1112ca8e63d314
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-02-16-19-35.gh-issue-158592.V6W21J.rst
@@ -0,0 +1 @@
+``del list[index]`` now triggers shrinking the list's internal array.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 87a669f203589d..a4ad1094ba51ce 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1182,7 +1182,7 @@ list_ass_item_lock_held(PyListObject *a, Py_ssize_t i, 
PyObject *v)
         if (i < size - 1) {
             list_shift_items_left_lock_held(a, i, size - 1);
         }
-        Py_SET_SIZE(a, size - 1);
+        list_resize(a, size - 1);  // NB: shrinking a list can't fail
     }
     else {
         FT_ATOMIC_STORE_PTR_RELEASE(a->ob_item[i], Py_NewRef(v));

_______________________________________________
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