diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-04 23:22:44 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-04 23:22:44 (GMT) |
commit | b9d4963a989accce30234b7b74bce874c0142209 (patch) | |
tree | 63fa25095a756b9def7c84cf7eb88d68c2412e29 /Lib/pprint.py | |
parent | b9c3ed4f82d3551c9906da55ddb8059ac3b5ce94 (diff) | |
download | cpython-b9d4963a989accce30234b7b74bce874c0142209.zip cpython-b9d4963a989accce30234b7b74bce874c0142209.tar.gz cpython-b9d4963a989accce30234b7b74bce874c0142209.tar.bz2 |
Issue #7092: Fix the DeprecationWarnings emitted by the standard library
when using the -3 flag. Patch by Florent Xicluna.
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r-- | Lib/pprint.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index c48465b..910283e 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -35,6 +35,7 @@ saferepr() """ import sys as _sys +import warnings from cStringIO import StringIO as _StringIO @@ -70,6 +71,13 @@ def isrecursive(object): """Determine if object requires a recursive representation.""" return _safe_repr(object, {}, None, 0)[2] +def _sorted(iterable): + with warnings.catch_warnings(): + if _sys.py3kwarning: + warnings.filterwarnings("ignore", "comparing unequal types " + "not supported", DeprecationWarning) + return sorted(iterable) + class PrettyPrinter: def __init__(self, indent=1, width=80, depth=None, stream=None): """Handle pretty printing operations onto a stream using a set of @@ -144,8 +152,7 @@ class PrettyPrinter: if length: context[objid] = 1 indent = indent + self._indent_per_level - items = object.items() - items.sort() + items = _sorted(object.items()) key, ent = items[0] rep = self._repr(key, context, level) write(rep) @@ -181,7 +188,7 @@ class PrettyPrinter: return write('set([') endchar = '])' - object = sorted(object) + object = _sorted(object) indent += 4 elif issubclass(typ, frozenset): if not length: @@ -189,7 +196,7 @@ class PrettyPrinter: return write('frozenset([') endchar = '])' - object = sorted(object) + object = _sorted(object) indent += 10 else: write('(') @@ -274,7 +281,7 @@ def _safe_repr(object, context, maxlevels, level): append = components.append level += 1 saferepr = _safe_repr - for k, v in sorted(object.items()): + 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)) |