Commit bf7a2660 authored by Raymond Hettinger's avatar Raymond Hettinger

Fixup repr for dict_proxy objects.

parent 470a4107
......@@ -4589,6 +4589,10 @@ class DictProxyTests(unittest.TestCase):
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() ]
......
......@@ -13,6 +13,8 @@ Core and Builtins
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
-------
......
......@@ -801,6 +801,20 @@ proxy_str(proxyobject *pp)
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 @@ PyTypeObject PyDictProxy_Type = {
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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment