At the PythonLabs meeting someone mentioned it would make Jim really

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.
This commit is contained in:
Guido van Rossum 2001-12-05 19:46:42 +00:00
parent 698da02d3b
commit d331cb5502
3 changed files with 7 additions and 8 deletions

View file

@ -812,13 +812,13 @@ subtype_setdict(PyObject *obj, PyObject *value, void *context)
"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;