]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 87368 via svnmerge from
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 18 Dec 2010 15:06:45 +0000 (15:06 +0000)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 18 Dec 2010 15:06:45 +0000 (15:06 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87368 | ezio.melotti | 2010-12-18 15:59:43 +0100 (Sat, 18 Dec 2010) | 1 line

  #5587: add a repr to dict_proxy objects.  Patch by David Stanek and Daniel Urban.
........

Lib/test/test_descr.py
Misc/NEWS
Objects/descrobject.c

index 9c26ed36010066f28c8dd9dbf9020d093469aeea..e1c928f1794cd7d6b03902d9e3bc088918550287 100644 (file)
@@ -4262,6 +4262,11 @@ class DictProxyTests(unittest.TestCase):
             pass
         self.assertEqual(type(C.__dict__), type(B.__dict__))
 
+    def test_repr(self):
+        # Testing dict_proxy.__repr__
+        dict_ = {k: v for k, v in self.C.__dict__.items()}
+        self.assertEqual(repr(self.C.__dict__), 'dict_proxy({!r})'.format(dict_))
+
 
 class PTypesLongInitTest(unittest.TestCase):
     # This is in its own TestCase so that it can be run before any other tests.
index e53aff0dcba36a9bac12b5d52d04ab2ef70e5dff..2c783121e67a42e8ec292c49e68912d0ed65f77a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,9 @@ Core and Builtins
   float.__divmod__ with respect to signed zeros.  -4.0 % 4.0 should be
   0.0, not -0.0.
 
+- Issue #5587: add a repr to dict_proxy objects.  Patch by David Stanek and
+  Daniel Urban.
+
 Library
 -------
 
index 5e592710245203fbd9b7fb8973d952b2b488e702..5f118ce09ed4788f47a8f799d075cb608576c170 100644 (file)
@@ -766,6 +766,12 @@ proxy_str(proxyobject *pp)
     return PyObject_Str(pp->dict);
 }
 
+static PyObject *
+proxy_repr(proxyobject *pp)
+{
+    return PyUnicode_FromFormat("dict_proxy(%R)", pp->dict);
+}
+
 static int
 proxy_traverse(PyObject *self, visitproc visit, void *arg)
 {
@@ -791,7 +797,7 @@ PyTypeObject PyDictProxy_Type = {
     0,                                          /* tp_getattr */
     0,                                          /* tp_setattr */
     0,                                          /* tp_reserved */
-    0,                                          /* tp_repr */
+    (reprfunc)proxy_repr,                       /* tp_repr */
     0,                                          /* tp_as_number */
     &proxy_as_sequence,                         /* tp_as_sequence */
     &proxy_as_mapping,                          /* tp_as_mapping */