Fixup repr for dict_proxy objects.
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index dc18f33..b5d9890 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4589,6 +4589,10 @@
pass
self.C = C
+ def test_repr(self):
+ self.assertIn('dict_proxy({', repr(vars(self.C)))
+ self.assertIn("'meth':", repr(vars(self.C)))
+
def test_iter_keys(self):
# Testing dict-proxy iterkeys...
keys = [ key for key in self.C.__dict__.iterkeys() ]
diff --git a/Misc/NEWS b/Misc/NEWS
index 024d38d..9f4ecc9 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,8 @@
the following case: sys.stdin.read() stopped with CTRL+d (end of file),
raw_input() interrupted by CTRL+c.
+- dict_proxy objects now display their contents rather than just the class name.
+
Library
-------
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 135b6d2..8e7ea7d 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -801,6 +801,20 @@
return PyObject_Str(pp->dict);
}
+static PyObject *
+proxy_repr(proxyobject *pp)
+{
+ PyObject *dictrepr;
+ PyObject *result;
+
+ dictrepr = PyObject_Repr(pp->dict);
+ if (dictrepr == NULL)
+ return NULL;
+ result = PyString_FromFormat("dict_proxy(%s)", PyString_AS_STRING(dictrepr));
+ Py_DECREF(dictrepr);
+ return result;
+}
+
static int
proxy_traverse(PyObject *self, visitproc visit, void *arg)
{
@@ -832,7 +846,7 @@
0, /* tp_getattr */
0, /* tp_setattr */
(cmpfunc)proxy_compare, /* tp_compare */
- 0, /* tp_repr */
+ (reprfunc)proxy_repr, /* tp_repr */
0, /* tp_as_number */
&proxy_as_sequence, /* tp_as_sequence */
&proxy_as_mapping, /* tp_as_mapping */