mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got displayed in seemingly random order (the hash-induced order produced by dict.__repr__). None of this was documented. Now pprint functions always sort dicts by key, and the docs promise it. This was proposed and agreed to during the PyCon 2006 core sprint -- I just didn't have time for it before now.
This commit is contained in:
parent
7f7386cfd2
commit
d609b1a20e
4 changed files with 42 additions and 5 deletions
|
@ -246,7 +246,7 @@ def _safe_repr(object, context, maxlevels, level):
|
|||
append = components.append
|
||||
level += 1
|
||||
saferepr = _safe_repr
|
||||
for k, v in object.iteritems():
|
||||
for k, v in sorted(object.items()):
|
||||
krepr, kreadable, krecur = saferepr(k, context, maxlevels, level)
|
||||
vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level)
|
||||
append("%s: %s" % (krepr, vrepr))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue