diff options
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r-- | Lib/pprint.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index 16d8eae..19b9661 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -90,9 +90,9 @@ class PrettyPrinter: """ indent = int(indent) width = int(width) - assert indent >= 0 + assert indent >= 0, "indent must be >= 0" assert depth is None or depth > 0, "depth must be > 0" - assert width + assert width, "width must be != 0" self._depth = depth self._indent_per_level = indent self._width = width @@ -130,7 +130,8 @@ class PrettyPrinter: write = stream.write if sepLines: - if typ is dict: + r = typ.__repr__ + if issubclass(typ, dict) and r is dict.__repr__: write('{') if self._indent_per_level > 1: write((self._indent_per_level - 1) * ' ') @@ -157,8 +158,9 @@ class PrettyPrinter: write('}') return - if typ is list or typ is tuple: - if typ is list: + if (issubclass(typ, list) and r is list.__repr__) or \ + (issubclass(typ, tuple) and r is tuple.__repr__): + if issubclass(typ, list): write('[') endchar = ']' else: @@ -179,7 +181,7 @@ class PrettyPrinter: allowance + 1, context, level) indent = indent - self._indent_per_level del context[objid] - if typ is tuple and length == 1: + if issubclass(typ, tuple) and length == 1: write(',') write(endchar) return @@ -226,7 +228,8 @@ def _safe_repr(object, context, maxlevels, level): write(qget(char, `char`[1:-1])) return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False - if typ is dict: + r = typ.__repr__ + if issubclass(typ, dict) and r is dict.__repr__: if not object: return "{}", True, False objid = _id(object) @@ -251,8 +254,9 @@ def _safe_repr(object, context, maxlevels, level): del context[objid] return "{%s}" % _commajoin(components), readable, recursive - if typ is list or typ is tuple: - if typ is list: + if (issubclass(typ, list) and r is list.__repr__) or \ + (issubclass(typ, tuple) and r is tuple.__repr__): + if issubclass(typ, list): if not object: return "[]", True, False format = "[%s]" |