diff options
author | Georg Brandl <georg@python.org> | 2008-05-12 16:26:52 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-05-12 16:26:52 (GMT) |
commit | 23da6e654586bd59af566c6ed5d3e89bc55e8b23 (patch) | |
tree | e5e5f089a061e30920217a4f61f4e16827f372c2 /Lib/pprint.py | |
parent | 103f19d286d7b0a80bd83031d8fd1c0af31dfd9e (diff) | |
download | cpython-23da6e654586bd59af566c6ed5d3e89bc55e8b23.zip cpython-23da6e654586bd59af566c6ed5d3e89bc55e8b23.tar.gz cpython-23da6e654586bd59af566c6ed5d3e89bc55e8b23.tar.bz2 |
#1713041: fix pprint's handling of maximum depth.
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r-- | Lib/pprint.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index 9f9d6a2..93d850a 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -131,6 +131,10 @@ class PrettyPrinter: sepLines = _len(rep) > (self._width - 1 - indent - allowance) write = stream.write + if self._depth and level > self._depth: + write(rep) + return + r = getattr(typ, "__repr__", None) if issubclass(typ, dict) and r is dict.__repr__: write('{') @@ -211,8 +215,8 @@ class PrettyPrinter: write(',') write(endchar) return - write(rep) + write(rep) def _repr(self, object, context, level): repr, readable, recursive = self.format(object, context.copy(), @@ -259,7 +263,7 @@ def _safe_repr(object, context, maxlevels, level): if not object: return "{}", True, False objid = _id(object) - if maxlevels and level > maxlevels: + if maxlevels and level >= maxlevels: return "{...}", False, objid in context if objid in context: return _recursion(object), False, True @@ -293,7 +297,7 @@ def _safe_repr(object, context, maxlevels, level): return "()", True, False format = "(%s)" objid = _id(object) - if maxlevels and level > maxlevels: + if maxlevels and level >= maxlevels: return format % "...", False, objid in context if objid in context: return _recursion(object), False, True |