Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d254f7

Browse files
committed
Merged revisions 87368 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent c79cf04 commit 9d254f7

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lib/test/test_descr.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4262,6 +4262,11 @@ class C(metaclass=M):
42624262
pass
42634263
self.assertEqual(type(C.__dict__), type(B.__dict__))
42644264

4265+
def test_repr(self):
4266+
# Testing dict_proxy.__repr__
4267+
dict_ = {k: v for k, v in self.C.__dict__.items()}
4268+
self.assertEqual(repr(self.C.__dict__), 'dict_proxy({!r})'.format(dict_))
4269+
42654270

42664271
class PTypesLongInitTest(unittest.TestCase):
42674272
# This is in its own TestCase so that it can be run before any other tests.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Core and Builtins
1818
float.__divmod__ with respect to signed zeros. -4.0 % 4.0 should be
1919
0.0, not -0.0.
2020

21+
- Issue #5587: add a repr to dict_proxy objects. Patch by David Stanek and
22+
Daniel Urban.
23+
2124
Library
2225
-------
2326

Objects/descrobject.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,12 @@ proxy_str(proxyobject *pp)
766766
return PyObject_Str(pp->dict);
767767
}
768768

769+
static PyObject *
770+
proxy_repr(proxyobject *pp)
771+
{
772+
return PyUnicode_FromFormat("dict_proxy(%R)", pp->dict);
773+
}
774+
769775
static int
770776
proxy_traverse(PyObject *self, visitproc visit, void *arg)
771777
{
@@ -791,7 +797,7 @@ PyTypeObject PyDictProxy_Type = {
791797
0, /* tp_getattr */
792798
0, /* tp_setattr */
793799
0, /* tp_reserved */
794-
0, /* tp_repr */
800+
(reprfunc)proxy_repr, /* tp_repr */
795801
0, /* tp_as_number */
796802
&proxy_as_sequence, /* tp_as_sequence */
797803
&proxy_as_mapping, /* tp_as_mapping */

0 commit comments

Comments
 (0)