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
d6da90f9
Commit
d6da90f9
authored
Jul 21, 2012
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with unorderable key.
parent
b4bbee25
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
Lib/pprint.py
Lib/pprint.py
+5
-1
Lib/test/test_pprint.py
Lib/test/test_pprint.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pprint.py
View file @
d6da90f9
...
...
@@ -86,7 +86,11 @@ class _safe_key:
self
.
obj
=
obj
def
__lt__
(
self
,
other
):
rv
=
self
.
obj
.
__lt__
(
other
.
obj
)
try
:
rv
=
self
.
obj
.
__lt__
(
other
.
obj
)
except
TypeError
:
rv
=
NotImplemented
if
rv
is
NotImplemented
:
rv
=
(
str
(
type
(
self
.
obj
)),
id
(
self
.
obj
))
<
\
(
str
(
type
(
other
.
obj
)),
id
(
other
.
obj
))
...
...
Lib/test/test_pprint.py
View file @
d6da90f9
...
...
@@ -462,6 +462,15 @@ class QueryTestCase(unittest.TestCase):
self
.
assertEqual
(
clean
(
pprint
.
pformat
(
dict
.
fromkeys
(
keys
))),
'{'
+
','
.
join
(
'%r:None'
%
k
for
k
in
skeys
)
+
'}'
)
# Issue 10017: TypeError on user-defined types as dict keys.
self
.
assertEqual
(
pprint
.
pformat
({
Unorderable
:
0
,
1
:
0
}),
'{1: 0, '
+
repr
(
Unorderable
)
+
': 0}'
)
# Issue 14998: TypeError on tuples with NoneTypes as dict keys.
self
.
assertEqual
(
pprint
.
pformat
({(
1
,):
0
,
(
None
,):
0
}),
'{(1,): 0, (None,): 0}'
)
class
DottedPrettyPrinter
(
pprint
.
PrettyPrinter
):
def
format
(
self
,
object
,
context
,
maxlevels
,
level
):
...
...
Misc/NEWS
View file @
d6da90f9
...
...
@@ -98,6 +98,9 @@ Core and Builtins
Library
-------
- Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with
user-defined types as keys or other unorderable keys.
- Issue #14635: telnetlib will use poll() rather than select() when possible
to avoid failing due to the select() file descriptor limit.
...
...
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