https://github.com/python/cpython/commit/796b26b360cd1955d1268f22d91081fa1a15afb7
commit: 796b26b360cd1955d1268f22d91081fa1a15afb7
branch: main
author: Peter Bierma <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-10-21T17:09:15Z
summary:

gh-114258: Use Argument Clinic for `__setitem__` (GH-160048)

files:
M Modules/_collectionsmodule.c
M Modules/_ctypes/_ctypes.c
M Modules/_ctypes/clinic/_ctypes.c.h
M Modules/_dbmmodule.c
M Modules/_gdbmmodule.c
M Modules/clinic/_collectionsmodule.c.h
M Modules/clinic/_dbmmodule.c.h
M Modules/clinic/_gdbmmodule.c.h
M Modules/clinic/mmapmodule.c.h
M Modules/mmapmodule.c
M Objects/bytearrayobject.c
M Objects/clinic/bytearrayobject.c.h
M Objects/clinic/listobject.c.h
M Objects/listobject.c
M Tools/clinic/libclinic/dsl_parser.py
M Tools/clinic/libclinic/slots.py

diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 19910dbc0a5d421..5a68a9ede44a6ad 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1499,8 +1499,19 @@ deque_remove_impl(dequeobject *deque, PyObject *value)
     Py_RETURN_NONE;
 }
 
+/*[clinic input]
+@critical_section
+_collections.deque.__setitem__ as deque_ass_item
+
+    deque: dequeobject
+    i: Py_ssize_t
+    v: object
+    /
+[clinic start generated code]*/
+
 static int
-deque_ass_item_lock_held(dequeobject *deque, Py_ssize_t i, PyObject *v)
+deque_ass_item_impl(dequeobject *deque, Py_ssize_t i, PyObject *v)
+/*[clinic end generated code: output=28739a830dc69ab1 input=b767e1a4972fa537]*/
 {
     block *b;
     Py_ssize_t n, len=Py_SIZE(deque), halflen=(len+1)>>1, index=i;
@@ -1531,17 +1542,6 @@ deque_ass_item_lock_held(dequeobject *deque, Py_ssize_t 
i, PyObject *v)
     return 0;
 }
 
-static int
-deque_ass_item(PyObject *self, Py_ssize_t i, PyObject *v)
-{
-    dequeobject *deque = dequeobject_CAST(self);
-    int result;
-    Py_BEGIN_CRITICAL_SECTION(deque);
-    result = deque_ass_item_lock_held(deque, i, v);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
-
 static void
 deque_dealloc(PyObject *self)
 {
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 39ca44790d4244f..af3748a0124ec51 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -4983,8 +4983,11 @@ static PyType_Spec pycunion_spec = {
 /*
   PyCArray_Type
 */
-static int Array_ass_item_lock_held(PyObject *, Py_ssize_t, PyObject *);
-static int Array_ass_subscript(PyObject *, PyObject *, PyObject *);
+
+/*[clinic input]
+class _ctypes.Array "PyObject *" "clinic_state()->PyCArray_Type"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b2d780e2e2dc6e8a]*/
 
 static int
 Array_init(PyObject *self, PyObject *args, PyObject *kw)
@@ -5008,7 +5011,7 @@ Array_init(PyObject *self, PyObject *args, PyObject *kw)
         for (i = 0; result >= 0 && i < n; ++i) {
             PyObject *v = PyTuple_GET_ITEM(args, i);
             assert(v != NULL);
-            result = Array_ass_item_lock_held(self, i, v);
+            result = Array_ass_item_impl(self, i, v);
         }
         Py_END_CRITICAL_SECTION();
         return result;
@@ -5192,8 +5195,19 @@ Array_subscript(PyObject *myself, PyObject *item)
     return result;
 }
 
+/*[clinic input]
+@critical_section
+_ctypes.Array.__setitem__ as Array_ass_item
+
+    myself: self
+    index: Py_ssize_t
+    value: object
+    /
+[clinic start generated code]*/
+
 static int
-Array_ass_item_lock_held(PyObject *myself, Py_ssize_t index, PyObject *value)
+Array_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value)
+/*[clinic end generated code: output=8fb1fd51b5b45da8 input=8b6ddb53d6377b96]*/
 {
     _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(myself);
 
@@ -5227,19 +5241,19 @@ Array_ass_item_lock_held(PyObject *myself, Py_ssize_t 
index, PyObject *value)
                        index, size, ptr);
 }
 
-static int
-Array_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
-{
-    int result;
-    Py_BEGIN_CRITICAL_SECTION(myself);
-    result = Array_ass_item_lock_held(myself, index, value);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
+/*[clinic input]
+@critical_section
+_ctypes.Array.__setitem__ as Array_ass_subscript
 
+    myself: self
+    item: object
+    value: object
+    /
+[clinic start generated code]*/
 
 static int
-Array_ass_subscript_lock_held(PyObject *myself, PyObject *item, PyObject 
*value)
+Array_ass_subscript_impl(PyObject *myself, PyObject *item, PyObject *value)
+/*[clinic end generated code: output=cb9a138e4e40c5ac input=4b7aedebbb357853]*/
 {
     CDataObject *self = _CDataObject_CAST(myself);
 
@@ -5256,7 +5270,7 @@ Array_ass_subscript_lock_held(PyObject *myself, PyObject 
*item, PyObject *value)
             return -1;
         if (i < 0)
             i += self->b_length;
-        return Array_ass_item_lock_held(myself, i, value);
+        return Array_ass_item_impl(myself, i, value);
     }
     else if (PySlice_Check(item)) {
         Py_ssize_t start, stop, step, slicelen, otherlen, i;
@@ -5281,7 +5295,7 @@ Array_ass_subscript_lock_held(PyObject *myself, PyObject 
*item, PyObject *value)
             int result;
             if (item == NULL)
                 return -1;
-            result = Array_ass_item_lock_held(myself, cur, item);
+            result = Array_ass_item_impl(myself, cur, item);
             Py_DECREF(item);
             if (result == -1)
                 return -1;
@@ -5295,17 +5309,6 @@ Array_ass_subscript_lock_held(PyObject *myself, PyObject 
*item, PyObject *value)
     }
 }
 
-static int
-Array_ass_subscript(PyObject *myself, PyObject *item, PyObject *value)
-{
-    int result;
-    Py_BEGIN_CRITICAL_SECTION(myself);
-    result = Array_ass_subscript_lock_held(myself, item, value);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
-
-
 static Py_ssize_t
 Array_length(PyObject *myself)
 {
@@ -5624,8 +5627,24 @@ Pointer_item(PyObject *self, Py_ssize_t index)
     return res;
 }
 
+/*[clinic input]
+class _ctypes._Pointer "PyObject *" "clinic_state()->PyCPointer_Type"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=452695db70aa7c3e]*/
+
+/*[clinic input]
+@critical_section
+_ctypes._Pointer.__setitem__ as Pointer_ass_item
+
+    myself: self
+    index: Py_ssize_t
+    value: object
+    /
+[clinic start generated code]*/
+
 static int
-Pointer_ass_item_lock_held(PyObject *myself, Py_ssize_t index, PyObject *value)
+Pointer_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value)
+/*[clinic end generated code: output=4503430bd55b6c69 input=344ad19b3094558c]*/
 {
     CDataObject *self = _CDataObject_CAST(myself);
     _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
@@ -5670,16 +5689,6 @@ Pointer_ass_item_lock_held(PyObject *myself, Py_ssize_t 
index, PyObject *value)
                        index, size, ((char *)deref + offset));
 }
 
-static int
-Pointer_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
-{
-    int res;
-    Py_BEGIN_CRITICAL_SECTION(self);
-    res = Pointer_ass_item_lock_held(self, index, value);
-    Py_END_CRITICAL_SECTION();
-    return res;
-}
-
 static PyObject *
 Pointer_get_contents_lock_held(PyObject *self, void *closure)
 {
diff --git a/Modules/_ctypes/clinic/_ctypes.c.h 
b/Modules/_ctypes/clinic/_ctypes.c.h
index fa9e30586a51d9a..4eb89baab4b809f 100644
--- a/Modules/_ctypes/clinic/_ctypes.c.h
+++ b/Modules/_ctypes/clinic/_ctypes.c.h
@@ -746,6 +746,36 @@ _ctypes_CFuncPtr_argtypes_get(PyObject *self, void 
*Py_UNUSED(context))
     return return_value;
 }
 
+static int
+Array_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value);
+
+static int
+Array_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(myself);
+    return_value = Array_ass_item_impl(myself, index, value);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
+static int
+Array_ass_subscript_impl(PyObject *myself, PyObject *item, PyObject *value);
+
+static int
+Array_ass_subscript(PyObject *myself, PyObject *item, PyObject *value)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(myself);
+    return_value = Array_ass_subscript_impl(myself, item, value);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 static int
 _ctypes_Simple_value_set_impl(CDataObject *self, PyObject *value);
 
@@ -804,6 +834,21 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, 
PyObject *const *args, Py
     }
     return Simple_from_outparm_impl(self, cls);
 }
+
+static int
+Pointer_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value);
+
+static int
+Pointer_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(myself);
+    return_value = Pointer_ass_item_impl(myself, index, value);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
 #define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", 
(getter)_ctypes_CType_Type___pointer_type___get, 
(setter)_ctypes_CType_Type___pointer_type___set, NULL},
 
 #define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", 
(getter)_ctypes_PyCArrayType_Type_raw_get, 
(setter)_ctypes_PyCArrayType_Type_raw_set, NULL},
@@ -818,4 +863,4 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, 
PyObject *const *args, Py
 
 #define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", 
(getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL},
 
-/*[clinic end generated code: output=fdf9a3519e34b6f4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f01123efc29f8ae0 input=a9049054013a1b77]*/
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 3186ce92749b1b1..cfc8340d26b79c0 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -224,12 +224,22 @@ dbm_subscript(PyObject *self, PyObject *key)
     return result;
 }
 
+/*[clinic input]
+@critical_section
+_dbm.dbm.__setitem__ as dbm_ass_sub
+
+    v: object
+    w: object
+    /
+[clinic start generated code]*/
+
 static int
-dbm_ass_sub_lock_held(PyObject *self, PyObject *v, PyObject *w)
+dbm_ass_sub_impl(dbmobject *self, PyObject *v, PyObject *w)
+/*[clinic end generated code: output=33e861810d1fd44a input=4f10cc93a02142ee]*/
 {
     datum krec, drec;
     Py_ssize_t tmp_size;
-    dbmobject *dp = dbmobject_CAST(self);
+    dbmobject *dp = self;
 
     if ( !PyArg_Parse(v, "s#", &krec.dptr, &tmp_size) ) {
         PyErr_SetString(PyExc_TypeError,
@@ -279,16 +289,6 @@ dbm_ass_sub_lock_held(PyObject *self, PyObject *v, 
PyObject *w)
     return 0;
 }
 
-static int
-dbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
-{
-    int result;
-    Py_BEGIN_CRITICAL_SECTION(self);
-    result = dbm_ass_sub_lock_held(self, v, w);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
-
 /*[clinic input]
 @critical_section
 _dbm.dbm.close
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index 0a15012e6eb01a8..fefbb59848c6382 100644
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -310,12 +310,22 @@ _gdbm_gdbm_get_impl(gdbmobject *self, PyObject *key, 
PyObject *default_value)
     return res;
 }
 
+/*[clinic input]
+@critical_section
+_gdbm.gdbm.__setitem__ as gdbm_ass_sub
+
+    v: object
+    w: object
+    /
+[clinic start generated code]*/
+
 static int
-gdbm_ass_sub_lock_held(PyObject *op, PyObject *v, PyObject *w)
+gdbm_ass_sub_impl(gdbmobject *self, PyObject *v, PyObject *w)
+/*[clinic end generated code: output=b46cce6ffa309dab input=fbd980f3b49e2f91]*/
 {
     datum krec, drec;
     const char *failmsg = "gdbm mappings have bytes or string indices only";
-    gdbmobject *dp = _gdbmobject_CAST(op);
+    gdbmobject *dp = self;
     _gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp));
 
     if (!parse_datum(v, &krec, failmsg)) {
@@ -356,16 +366,6 @@ gdbm_ass_sub_lock_held(PyObject *op, PyObject *v, PyObject 
*w)
     return 0;
 }
 
-static int
-gdbm_ass_sub(PyObject *op, PyObject *v, PyObject *w)
-{
-    int result;
-    Py_BEGIN_CRITICAL_SECTION(op);
-    result = gdbm_ass_sub_lock_held(op, v, w);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
-
 /*[clinic input]
 @permit_long_summary
 @critical_section
diff --git a/Modules/clinic/_collectionsmodule.c.h 
b/Modules/clinic/_collectionsmodule.c.h
index 6c60678a6fbd51a..b179555f9873619 100644
--- a/Modules/clinic/_collectionsmodule.c.h
+++ b/Modules/clinic/_collectionsmodule.c.h
@@ -434,6 +434,21 @@ deque_remove(PyObject *deque, PyObject *value)
     return return_value;
 }
 
+static int
+deque_ass_item_impl(dequeobject *deque, Py_ssize_t i, PyObject *v);
+
+static int
+deque_ass_item(PyObject *deque, Py_ssize_t i, PyObject *v)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(deque);
+    return_value = deque_ass_item_impl((dequeobject *)deque, i, v);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 PyDoc_STRVAR(deque___reduce____doc__,
 "__reduce__($self, /)\n"
 "--\n"
@@ -632,4 +647,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, 
PyObject *kwargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=f5a388add99d3d15 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1bdec9485a9d40fb input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h
index 4e1a9eaa741e4e5..1287254421a432b 100644
--- a/Modules/clinic/_dbmmodule.c.h
+++ b/Modules/clinic/_dbmmodule.c.h
@@ -21,6 +21,21 @@ dbm_length(PyObject *self)
     return return_value;
 }
 
+static int
+dbm_ass_sub_impl(dbmobject *self, PyObject *v, PyObject *w);
+
+static int
+dbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = dbm_ass_sub_impl((dbmobject *)self, v, w);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 PyDoc_STRVAR(_dbm_dbm_close__doc__,
 "close($self, /)\n"
 "--\n"
@@ -264,4 +279,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t 
nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=7ae22ba4a7aeffa2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=da6b5d201f8d3853 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h
index 55e2100751f0906..7549d3001d0f3ec 100644
--- a/Modules/clinic/_gdbmmodule.c.h
+++ b/Modules/clinic/_gdbmmodule.c.h
@@ -55,6 +55,21 @@ _gdbm_gdbm_get(PyObject *self, PyObject *const *args, 
Py_ssize_t nargs)
     return return_value;
 }
 
+static int
+gdbm_ass_sub_impl(gdbmobject *self, PyObject *v, PyObject *w);
+
+static int
+gdbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = gdbm_ass_sub_impl((gdbmobject *)self, v, w);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 PyDoc_STRVAR(_gdbm_gdbm_setdefault__doc__,
 "setdefault($self, key, default=None, /)\n"
 "--\n"
@@ -416,4 +431,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t 
nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=36e1ed1cc3523aeb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6f91f162b0f822d3 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/mmapmodule.c.h b/Modules/clinic/mmapmodule.c.h
index 9874ab2b3de0a96..4bb40541b254b8a 100644
--- a/Modules/clinic/mmapmodule.c.h
+++ b/Modules/clinic/mmapmodule.c.h
@@ -877,6 +877,36 @@ mmap_length(PyObject *self)
     return return_value;
 }
 
+static int
+mmap_ass_item_impl(mmap_object *self, Py_ssize_t i, PyObject *v);
+
+static int
+mmap_ass_item(PyObject *self, Py_ssize_t i, PyObject *v)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = mmap_ass_item_impl((mmap_object *)self, i, v);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
+static int
+mmap_ass_subscript_impl(mmap_object *self, PyObject *item, PyObject *value);
+
+static int
+mmap_ass_subscript(PyObject *self, PyObject *item, PyObject *value)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = mmap_ass_subscript_impl((mmap_object *)self, item, value);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 #ifndef MMAP_MMAP_RESIZE_METHODDEF
     #define MMAP_MMAP_RESIZE_METHODDEF
 #endif /* !defined(MMAP_MMAP_RESIZE_METHODDEF) */
@@ -892,4 +922,4 @@ mmap_length(PyObject *self)
 #ifndef MMAP_MMAP_MADVISE_METHODDEF
     #define MMAP_MMAP_MADVISE_METHODDEF
 #endif /* !defined(MMAP_MMAP_MADVISE_METHODDEF) */
-/*[clinic end generated code: output=e52bf0f914c90a96 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=eb09e5d722968cef input=a9049054013a1b77]*/
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 124245e4bec1057..4ea628b5d4a7525 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1599,11 +1599,20 @@ mmap_subscript(PyObject *op, PyObject *item)
     return result;
 }
 
+/*[clinic input]
+@critical_section
+mmap.mmap.__setitem__ as mmap_ass_item
+
+    i: Py_ssize_t
+    v: object
+    /
+[clinic start generated code]*/
+
 static int
-mmap_ass_item_lock_held(PyObject *op, Py_ssize_t i, PyObject *v)
+mmap_ass_item_impl(mmap_object *self, Py_ssize_t i, PyObject *v)
+/*[clinic end generated code: output=398d9d502e560f58 input=5fe8a60de3a6c39e]*/
 {
     const char *buf;
-    mmap_object *self = mmap_object_CAST(op);
 
     CHECK_VALID(-1);
     if (i < 0 || i >= self->size) {
@@ -1630,21 +1639,19 @@ mmap_ass_item_lock_held(PyObject *op, Py_ssize_t i, 
PyObject *v)
     return 0;
 }
 
-static int
-mmap_ass_item(PyObject *op, Py_ssize_t i, PyObject *v)
-{
-    int result;
-    Py_BEGIN_CRITICAL_SECTION(op);
-    result = mmap_ass_item_lock_held(op, i, v);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
+/*[clinic input]
+@critical_section
+mmap.mmap.__setitem__ as mmap_ass_subscript
+
+    item: object
+    value: object
+    /
+[clinic start generated code]*/
 
 static int
-mmap_ass_subscript_lock_held(PyObject *op, PyObject *item, PyObject *value)
+mmap_ass_subscript_impl(mmap_object *self, PyObject *item, PyObject *value)
+/*[clinic end generated code: output=e346a1c7f35800d4 input=4827c15e710601f0]*/
 {
-    mmap_object *self = mmap_object_CAST(op);
-
     if (!is_writable(self))
         return -1;
 
@@ -1743,16 +1750,6 @@ mmap_ass_subscript_lock_held(PyObject *op, PyObject 
*item, PyObject *value)
     }
 }
 
-static int
-mmap_ass_subscript(PyObject *op, PyObject *item, PyObject *value)
-{
-    int result;
-    Py_BEGIN_CRITICAL_SECTION(op);
-    result = mmap_ass_subscript_lock_held(op, item, value);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
-
 static PyObject *
 new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict);
 
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 429b8d993867f0c..a8e35d217dc54da 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -743,11 +743,21 @@ bytearray_setslice(PyByteArrayObject *self, Py_ssize_t 
lo, Py_ssize_t hi,
     return res;
 }
 
+/*[clinic input]
+@critical_section
+bytearray.__setitem__ as bytearray_setitem
+
+    i: Py_ssize_t
+    value: object
+    /
+[clinic start generated code]*/
+
 static int
-bytearray_setitem_lock_held(PyObject *op, Py_ssize_t i, PyObject *value)
+bytearray_setitem_impl(PyByteArrayObject *self, Py_ssize_t i,
+                       PyObject *value)
+/*[clinic end generated code: output=c8e973819dd58098 input=460a77c3d8b7268f]*/
 {
-    _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
-    PyByteArrayObject *self = _PyByteArray_CAST(op);
+    _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
 
     // GH-91153: We need to do this *before* the size check, in case value has 
a
     // nasty __index__ method that changes the size of the bytearray:
@@ -774,16 +784,6 @@ bytearray_setitem_lock_held(PyObject *op, Py_ssize_t i, 
PyObject *value)
     return 0;
 }
 
-static int
-bytearray_setitem(PyObject *op, Py_ssize_t i, PyObject *value)
-{
-    int ret;
-    Py_BEGIN_CRITICAL_SECTION(op);
-    ret = bytearray_setitem_lock_held(op, i, value);
-    Py_END_CRITICAL_SECTION();
-    return ret;
-}
-
 static int
 bytearray_ass_subscript_lock_held(PyObject *op, PyObject *index, PyObject 
*values)
 {
diff --git a/Objects/clinic/bytearrayobject.c.h 
b/Objects/clinic/bytearrayobject.c.h
index 9c8ba841200f306..83cfa00d59044e9 100644
--- a/Objects/clinic/bytearrayobject.c.h
+++ b/Objects/clinic/bytearrayobject.c.h
@@ -11,6 +11,22 @@ preserve
 #include "pycore_runtime.h"       // _Py_SINGLETON()
 #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL()
 
+static int
+bytearray_setitem_impl(PyByteArrayObject *self, Py_ssize_t i,
+                       PyObject *value);
+
+static int
+bytearray_setitem(PyObject *self, Py_ssize_t i, PyObject *value)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = bytearray_setitem_impl((PyByteArrayObject *)self, i, value);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 static int
 bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
                         const char *encoding, const char *errors);
@@ -1946,4 +1962,4 @@ bytearray_sizeof(PyObject *self, PyObject 
*Py_UNUSED(ignored))
 {
     return bytearray_sizeof_impl((PyByteArrayObject *)self);
 }
-/*[clinic end generated code: output=b67d1f1e84c7ed0f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a16aaa01f1fcf5a6 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h
index f3821ef5f70c21c..dc76baa17de7b9f 100644
--- a/Objects/clinic/listobject.c.h
+++ b/Objects/clinic/listobject.c.h
@@ -10,6 +10,21 @@ preserve
 #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
 
+static int
+list_ass_item_impl(PyListObject *a, Py_ssize_t i, PyObject *v);
+
+static int
+list_ass_item(PyObject *a, Py_ssize_t i, PyObject *v)
+{
+    int return_value = -1;
+
+    Py_BEGIN_CRITICAL_SECTION(a);
+    return_value = list_ass_item_impl((PyListObject *)a, i, v);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 PyDoc_STRVAR(list_insert__doc__,
 "insert($self, index, object, /)\n"
 "--\n"
@@ -468,4 +483,4 @@ list___reversed__(PyObject *self, PyObject 
*Py_UNUSED(ignored))
 {
     return list___reversed___impl((PyListObject *)self);
 }
-/*[clinic end generated code: output=06c21b0bffbe8d84 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ef8a058598f58f7e input=a9049054013a1b77]*/
diff --git a/Objects/listobject.c b/Objects/listobject.c
index f9488cc5c384bab..f974b3ba1200086 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1189,8 +1189,19 @@ list_inplace_repeat(PyObject *_self, Py_ssize_t n)
     return ret;
 }
 
+/*[clinic input]
+@critical_section
+list.__setitem__ as list_ass_item
+
+    a: self(type="PyListObject *")
+    i: Py_ssize_t
+    v: object
+    /
+[clinic start generated code]*/
+
 static int
-list_ass_item_lock_held(PyListObject *a, Py_ssize_t i, PyObject *v)
+list_ass_item_impl(PyListObject *a, Py_ssize_t i, PyObject *v)
+/*[clinic end generated code: output=51d8b4f1790b67db input=0ba2adeaf8b3d5a0]*/
 {
     if (!valid_index(i, Py_SIZE(a))) {
         PyErr_SetString(PyExc_IndexError,
@@ -1212,17 +1223,6 @@ list_ass_item_lock_held(PyListObject *a, Py_ssize_t i, 
PyObject *v)
     return 0;
 }
 
-static int
-list_ass_item(PyObject *aa, Py_ssize_t i, PyObject *v)
-{
-    int ret;
-    PyListObject *a = (PyListObject *)aa;
-    Py_BEGIN_CRITICAL_SECTION(a);
-    ret = list_ass_item_lock_held(a, i, v);
-    Py_END_CRITICAL_SECTION();
-    return ret;
-}
-
 /*[clinic input]
 @critical_section
 list.insert
@@ -3796,7 +3796,7 @@ list_ass_subscript_lock_held(PyObject *_self, PyObject 
*item, PyObject *value)
             return -1;
         if (i < 0)
             i += PyList_GET_SIZE(self);
-        return list_ass_item_lock_held(self, i, value);
+        return list_ass_item_impl(self, i, value);
     }
     else if (PySlice_Check(item)) {
         Py_ssize_t start, stop, step;
diff --git a/Tools/clinic/libclinic/dsl_parser.py 
b/Tools/clinic/libclinic/dsl_parser.py
index 4a38cb6b314fff0..819851dcb78aaad 100644
--- a/Tools/clinic/libclinic/dsl_parser.py
+++ b/Tools/clinic/libclinic/dsl_parser.py
@@ -98,7 +98,6 @@
 __rtruediv__
 __rxor__
 __setattr__
-__setitem__
 __str__
 __sub__
 __truediv__
diff --git a/Tools/clinic/libclinic/slots.py b/Tools/clinic/libclinic/slots.py
index 95137800fd868c0..6f7c9954a6d02a2 100644
--- a/Tools/clinic/libclinic/slots.py
+++ b/Tools/clinic/libclinic/slots.py
@@ -40,4 +40,5 @@ def make_return_converter(self) -> CReturnConverter:
 SLOTS: Final[dict[str, SlotSpec]] = {
     '__next__': SlotSpec(return_converter='object'),
     '__len__': SlotSpec(return_converter='Py_ssize_t'),
+    '__setitem__': SlotSpec(return_converter='int'),
 }

_______________________________________________
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