bpo-42088: Use "SimpleNamespace(...)" in the repr for SimpleNamespace

The repr is now "SimpleNamespace(...)" instead of "namespace(...)".
This commit is contained in:
Zackery Spytz 2020-11-24 13:56:59 -07:00
parent 0ec34cab9d
commit 0a1d2e7b59
4 changed files with 7 additions and 5 deletions

View File

@ -396,12 +396,12 @@ mappingproxy(OrderedDict([('the', 0),
def test_empty_simple_namespace(self):
ns = types.SimpleNamespace()
formatted = pprint.pformat(ns)
self.assertEqual(formatted, "namespace()")
self.assertEqual(formatted, "SimpleNamespace()")
def test_small_simple_namespace(self):
ns = types.SimpleNamespace(a=1, b=2)
formatted = pprint.pformat(ns)
self.assertEqual(formatted, "namespace(a=1, b=2)")
self.assertEqual(formatted, "SimpleNamespace(a=1, b=2)")
def test_simple_namespace(self):
ns = types.SimpleNamespace(

View File

@ -1406,7 +1406,7 @@ class SimpleNamespaceTests(unittest.TestCase):
ns2 = types.SimpleNamespace()
ns2.x = "spam"
ns2._y = 5
name = "namespace"
name = "SimpleNamespace"
self.assertEqual(repr(ns1), "{name}(x=1, y=2, w=3)".format(name=name))
self.assertEqual(repr(ns2), "{name}(x='spam', _y=5)".format(name=name))
@ -1456,7 +1456,7 @@ class SimpleNamespaceTests(unittest.TestCase):
ns1.spam = ns1
ns2.spam = ns3
ns3.spam = ns2
name = "namespace"
name = "SimpleNamespace"
repr1 = "{name}(c='cookie', spam={name}(...))".format(name=name)
repr2 = "{name}(spam={name}(x=1, spam={name}(...)))".format(name=name)

View File

@ -0,0 +1,2 @@
The repr of :class:`types.SimpleNamespace` is now ``SimpleNamespace(...)``
instead of ``namespace(...)``.

View File

@ -72,7 +72,7 @@ namespace_repr(PyObject *ns)
PyObject *separator, *pairsrepr, *repr = NULL;
const char * name;
name = Py_IS_TYPE(ns, &_PyNamespace_Type) ? "namespace"
name = Py_IS_TYPE(ns, &_PyNamespace_Type) ? "SimpleNamespace"
: Py_TYPE(ns)->tp_name;
i = Py_ReprEnter(ns);