add a __dict__ descr for IOBase (closes #12878)

This commit is contained in:
Benjamin Peterson 2011-09-03 09:26:20 -04:00
parent 7335e6f3e8
commit f6f3a35447
3 changed files with 27 additions and 0 deletions

View file

@ -156,6 +156,19 @@ iobase_closed_get(PyObject *self, void *context)
return PyBool_FromLong(IS_CLOSED(self));
}
static PyObject *
iobase_get_dict(PyObject *self)
{
PyObject **dictptr = _PyObject_GetDictPtr(self);
PyObject *dict;
assert(dictptr);
dict = *dictptr;
if (dict == NULL)
dict = *dictptr = PyDict_New();
Py_XINCREF(dict);
return dict;
}
PyObject *
_PyIOBase_check_closed(PyObject *self, PyObject *args)
{
@ -691,6 +704,7 @@ static PyMethodDef iobase_methods[] = {
};
static PyGetSetDef iobase_getset[] = {
{"__dict__", iobase_get_dict, NULL, NULL},
{"closed", (getter)iobase_closed_get, NULL, NULL},
{NULL}
};