Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bf7a2660
Commit
bf7a2660
authored
Jun 30, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixup repr for dict_proxy objects.
parent
470a4107
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
Lib/test/test_descr.py
Lib/test/test_descr.py
+4
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/descrobject.c
Objects/descrobject.c
+15
-1
No files found.
Lib/test/test_descr.py
View file @
bf7a2660
...
...
@@ -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
()
]
...
...
Misc/NEWS
View file @
bf7a2660
...
...
@@ -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
-------
...
...
Objects/descrobject.c
View file @
bf7a2660
...
...
@@ -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 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment