Skip to content

Commit

Permalink
Implement __set__ to make tuplegetter a data descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogsal committed Dec 29, 2018
1 parent 96eae4c commit 9838c39
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,17 @@ tuplegetterdescr_get(PyObject *self, PyObject *obj, PyObject *type)
return result;
}

static int
tuplegetter_set(PyObject *self, PyObject *obj, PyObject *value)
{
if (value == NULL) {
PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
} else {
PyErr_SetString(PyExc_AttributeError, "can't set attribute");
}
return -1;
}

static int
tuplegetter_traverse(PyObject *self, visitproc visit, void *arg)
{
Expand Down Expand Up @@ -2462,7 +2473,7 @@ static PyTypeObject tuplegetter_type = {
0, /* tp_base */
0, /* tp_dict */
tuplegetterdescr_get, /* tp_descr_get */
0, /* tp_descr_set */
tuplegetter_set, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
Expand Down

0 comments on commit 9838c39

Please sign in to comment.