summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-10-26 04:26:12 (GMT)
committerGuido van Rossum <guido@python.org>2001-10-26 04:26:12 (GMT)
commit6661be3bedf7ad0da8d33487672a227eb6bee6f1 (patch)
treea9915bc35a9dbc759b3843f9a11aa8aed0f6b6fb /Objects
parent0afde13b435f484ecbc3e95107d2318415f21d29 (diff)
downloadcpython-6661be3bedf7ad0da8d33487672a227eb6bee6f1.zip
cpython-6661be3bedf7ad0da8d33487672a227eb6bee6f1.tar.gz
cpython-6661be3bedf7ad0da8d33487672a227eb6bee6f1.tar.bz2
Allow assignment to newinstance.__dict__.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 5952b4e..ba2834a 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -674,8 +674,31 @@ subtype_dict(PyObject *obj, void *context)
return dict;
}
+static int
+subtype_setdict(PyObject *obj, PyObject *value, void *context)
+{
+ PyObject **dictptr = _PyObject_GetDictPtr(obj);
+ PyObject *dict;
+
+ if (dictptr == NULL) {
+ PyErr_SetString(PyExc_AttributeError,
+ "This object has no __dict__");
+ return -1;
+ }
+ if (value == NULL || !PyDict_Check(value)) {
+ PyErr_SetString(PyExc_TypeError,
+ "__dict__ must be set to a dictionary");
+ return -1;
+ }
+ dict = *dictptr;
+ Py_INCREF(value);
+ *dictptr = value;
+ Py_XDECREF(dict);
+ return 0;
+}
+
static PyGetSetDef subtype_getsets[] = {
- {"__dict__", subtype_dict, NULL, NULL},
+ {"__dict__", subtype_dict, subtype_setdict, NULL},
{0},
};