merge for issue #16160: Subclass support now works for types.SimpleNamespace.
This commit is contained in:
commit
42da889fec
|
@ -1135,6 +1135,15 @@ class SimpleNamespaceTests(unittest.TestCase):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
ns['spam']
|
ns['spam']
|
||||||
|
|
||||||
|
def test_subclass(self):
|
||||||
|
class Spam(types.SimpleNamespace):
|
||||||
|
pass
|
||||||
|
|
||||||
|
spam = Spam(ham=8, eggs=9)
|
||||||
|
|
||||||
|
self.assertIs(type(spam), Spam)
|
||||||
|
self.assertEqual(vars(spam), {'ham': 8, 'eggs': 9})
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(TypesTests, MappingProxyTests, ClassCreationTests,
|
run_unittest(TypesTests, MappingProxyTests, ClassCreationTests,
|
||||||
|
|
|
@ -16,6 +16,8 @@ Core and Builtins
|
||||||
- Issue #14783: Improve int() docstring and switch docstrings for str(),
|
- Issue #14783: Improve int() docstring and switch docstrings for str(),
|
||||||
range(), and slice() to use multi-line signatures.
|
range(), and slice() to use multi-line signatures.
|
||||||
|
|
||||||
|
- Issue #16160: Subclass support now works for types.SimpleNamespace.
|
||||||
|
|
||||||
- Upgrade Unicode data (UCD) to version 6.2.
|
- Upgrade Unicode data (UCD) to version 6.2.
|
||||||
|
|
||||||
- Issue #15379: Fix passing of non-BMP characters as integers for the charmap
|
- Issue #15379: Fix passing of non-BMP characters as integers for the charmap
|
||||||
|
|
|
@ -21,19 +21,19 @@ static PyMemberDef namespace_members[] = {
|
||||||
static PyObject *
|
static PyObject *
|
||||||
namespace_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
namespace_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
_PyNamespaceObject *ns;
|
PyObject *self;
|
||||||
ns = PyObject_GC_New(_PyNamespaceObject, &_PyNamespace_Type);
|
|
||||||
if (ns == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ns->ns_dict = PyDict_New();
|
assert(type != NULL && type->tp_alloc != NULL);
|
||||||
if (ns->ns_dict == NULL) {
|
self = type->tp_alloc(type, 0);
|
||||||
Py_DECREF(ns);
|
if (self != NULL) {
|
||||||
return NULL;
|
_PyNamespaceObject *ns = (_PyNamespaceObject *)self;
|
||||||
|
ns->ns_dict = PyDict_New();
|
||||||
|
if (ns->ns_dict == NULL) {
|
||||||
|
Py_DECREF(ns);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return self;
|
||||||
PyObject_GC_Track(ns);
|
|
||||||
return (PyObject *)ns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue