Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b8d7bd

Browse files
committed
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
1 parent 388f37e commit 2b8d7bd

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Objects/typeobject.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,9 +1504,26 @@ wrap_intobjargproc(PyObject *self, PyObject *args, void *wrapped)
15041504
return Py_None;
15051505
}
15061506

1507+
static PyObject *
1508+
wrap_delitem_int(PyObject *self, PyObject *args, void *wrapped)
1509+
{
1510+
intobjargproc func = (intobjargproc)wrapped;
1511+
int i, res;
1512+
1513+
if (!PyArg_ParseTuple(args, "i", &i))
1514+
return NULL;
1515+
res = (*func)(self, i, NULL);
1516+
if (res == -1 && PyErr_Occurred())
1517+
return NULL;
1518+
Py_INCREF(Py_None);
1519+
return Py_None;
1520+
}
1521+
15071522
static struct wrapperbase tab_setitem_int[] = {
15081523
{"__setitem__", (wrapperfunc)wrap_intobjargproc,
15091524
"x.__setitem__(i, y) <==> x[i]=y"},
1525+
{"__delitem__", (wrapperfunc)wrap_delitem_int,
1526+
"x.__delitem__(y) <==> del x[y]"},
15101527
{0}
15111528
};
15121529

@@ -1570,9 +1587,27 @@ wrap_objobjargproc(PyObject *self, PyObject *args, void *wrapped)
15701587
return Py_None;
15711588
}
15721589

1590+
static PyObject *
1591+
wrap_delitem(PyObject *self, PyObject *args, void *wrapped)
1592+
{
1593+
objobjargproc func = (objobjargproc)wrapped;
1594+
int res;
1595+
PyObject *key;
1596+
1597+
if (!PyArg_ParseTuple(args, "O", &key))
1598+
return NULL;
1599+
res = (*func)(self, key, NULL);
1600+
if (res == -1 && PyErr_Occurred())
1601+
return NULL;
1602+
Py_INCREF(Py_None);
1603+
return Py_None;
1604+
}
1605+
15731606
static struct wrapperbase tab_setitem[] = {
15741607
{"__setitem__", (wrapperfunc)wrap_objobjargproc,
15751608
"x.__setitem__(y, z) <==> x[y]=z"},
1609+
{"__delitem__", (wrapperfunc)wrap_delitem,
1610+
"x.__delitem__(y) <==> del x[y]"},
15761611
{0}
15771612
};
15781613

0 commit comments

Comments
 (0)