mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
use new generic __dict__ descriptor implementations
This commit is contained in:
parent
8eb1269c34
commit
23d7f12ffb
4 changed files with 6 additions and 141 deletions
|
@ -155,44 +155,8 @@ static PyMemberDef partial_memberlist[] = {
|
|||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
partial_get_dict(partialobject *pto)
|
||||
{
|
||||
if (pto->dict == NULL) {
|
||||
pto->dict = PyDict_New();
|
||||
if (pto->dict == NULL)
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(pto->dict);
|
||||
return pto->dict;
|
||||
}
|
||||
|
||||
static int
|
||||
partial_set_dict(partialobject *pto, PyObject *value)
|
||||
{
|
||||
PyObject *tmp;
|
||||
|
||||
/* It is illegal to del p.__dict__ */
|
||||
if (value == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"a partial object's dictionary may not be deleted");
|
||||
return -1;
|
||||
}
|
||||
/* Can only set __dict__ to a dictionary */
|
||||
if (!PyDict_Check(value)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"setting partial object's dictionary to a non-dict");
|
||||
return -1;
|
||||
}
|
||||
tmp = pto->dict;
|
||||
Py_INCREF(value);
|
||||
pto->dict = value;
|
||||
Py_XDECREF(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyGetSetDef partial_getsetlist[] = {
|
||||
{"__dict__", (getter)partial_get_dict, (setter)partial_set_dict},
|
||||
{"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue