happy if one could delete the __dict__ attribute of an instance. I
love to make Jim happy, so here goes...
- New-style objects now support deleting their __dict__. This is for
all intents and purposes equivalent to assigning a brand new empty
dictionary, but saves space if the object is not used further.
cant(a, None)
cant(a, [])
cant(a, 1)
- try:
- del a.__dict__
- except TypeError:
- pass
- else:
- raise TestFailed, "shouldn't allow del %r.__dict__" % (a)
+ del a.__dict__ # Deleting __dict__ is allowed
# Classes don't allow __dict__ assignment
cant(C, {})
dict.__hash__ and list.__hash__ now raises the same TypeError
(previously, these were the same as object.__hash__).
+- New-style objects now support deleting their __dict__. This is for
+ all intents and purposes equivalent to assigning a brand new empty
+ dictionary, but saves space if the object is not used further.
+
Core and builtins
Extension modules
"This object has no __dict__");
return -1;
}
- if (value == NULL || !PyDict_Check(value)) {
+ if (value != NULL && !PyDict_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"__dict__ must be set to a dictionary");
return -1;
}
dict = *dictptr;
- Py_INCREF(value);
+ Py_XINCREF(value);
*dictptr = value;
Py_XDECREF(dict);
return 0;