summaryrefslogtreecommitdiffstats
path: root/Lib/pprint.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-09-09 12:31:00 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-09-09 12:31:00 (GMT)
commitbad3c88094f43f3bc7dcce22f47b8c2a8dddabcf (patch)
treee315bcea2939b788711b87a7a9595cddfa7f0281 /Lib/pprint.py
parenta0e79408bcf14015995fb4f1f1c3ad88df017496 (diff)
downloadcpython-bad3c88094f43f3bc7dcce22f47b8c2a8dddabcf.zip
cpython-bad3c88094f43f3bc7dcce22f47b8c2a8dddabcf.tar.gz
cpython-bad3c88094f43f3bc7dcce22f47b8c2a8dddabcf.tar.bz2
Have pprint() respect the order in an OrderedDict.
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r--Lib/pprint.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py
index b3a6446..b8417f5 100644
--- a/Lib/pprint.py
+++ b/Lib/pprint.py
@@ -35,7 +35,7 @@ saferepr()
"""
import sys as _sys
-
+from collections import OrderedDict as _OrderedDict
from io import StringIO as _StringIO
__all__ = ["pprint","pformat","isreadable","isrecursive","saferepr",
@@ -163,7 +163,7 @@ class PrettyPrinter:
if sepLines:
r = getattr(typ, "__repr__", None)
- if issubclass(typ, dict) and r is dict.__repr__:
+ if issubclass(typ, dict):
write('{')
if self._indent_per_level > 1:
write((self._indent_per_level - 1) * ' ')
@@ -171,7 +171,10 @@ class PrettyPrinter:
if length:
context[objid] = 1
indent = indent + self._indent_per_level
- items = sorted(object.items(), key=_safe_tuple)
+ if issubclass(typ, _OrderedDict):
+ items = list(object.items())
+ else:
+ items = sorted(object.items(), key=_safe_tuple)
key, ent = items[0]
rep = self._repr(key, context, level)
write(rep)