Mercurial > cpython-lru_cache-weakref
diff Lib/pprint.py @ 38546:2eb8be0f8731 legacy-trunk
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.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Fri, 02 Jun 2006 23:22:51 +0000 |
| parents | ee3e0ee1edca |
| children | 942e4b42da14 13d5e5f0e993 |
line wrap: on
line diff
--- a/Lib/pprint.py Fri Jun 02 13:03:43 2006 +0000 +++ b/Lib/pprint.py Fri Jun 02 23:22:51 2006 +0000 @@ -246,7 +246,7 @@ 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))
