diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2012-10-17 05:35:38 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2012-10-17 05:35:38 (GMT) |
commit | 547298c94cd491dbfaa7bc5f968c2bdcf91588cc (patch) | |
tree | ec3b7ab445ce7b9042990843536fd930fe9863dd /Objects | |
parent | e54c7185727ca7e46abc6484181c781ff5b0a4eb (diff) | |
download | cpython-547298c94cd491dbfaa7bc5f968c2bdcf91588cc.zip cpython-547298c94cd491dbfaa7bc5f968c2bdcf91588cc.tar.gz cpython-547298c94cd491dbfaa7bc5f968c2bdcf91588cc.tar.bz2 |
Close #16160: Subclass support now works for types.SimpleNamespace. Thanks to RDM for noticing.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/namespaceobject.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index 753874c..ff278d3 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -21,19 +21,19 @@ static PyMemberDef namespace_members[] = { static PyObject * namespace_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - _PyNamespaceObject *ns; - ns = PyObject_GC_New(_PyNamespaceObject, &_PyNamespace_Type); - if (ns == NULL) - return NULL; - - ns->ns_dict = PyDict_New(); - if (ns->ns_dict == NULL) { - Py_DECREF(ns); - return NULL; + PyObject *self; + + assert(type != NULL && type->tp_alloc != NULL); + self = type->tp_alloc(type, 0); + if (self != NULL) { + _PyNamespaceObject *ns = (_PyNamespaceObject *)self; + ns->ns_dict = PyDict_New(); + if (ns->ns_dict == NULL) { + Py_DECREF(ns); + return NULL; + } } - - PyObject_GC_Track(ns); - return (PyObject *)ns; + return self; } |