Index: Lib/pprint.py =================================================================== --- Lib/pprint.py (revision 55224) +++ Lib/pprint.py (working copy) @@ -235,7 +235,7 @@ 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 @@ -269,7 +269,7 @@ 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 Index: Lib/test/test_pprint.py =================================================================== --- Lib/test/test_pprint.py (revision 55224) +++ Lib/test/test_pprint.py (working copy) @@ -195,7 +195,21 @@ others.should.not.be: like.this}""" self.assertEqual(DottedPrettyPrinter().pformat(o), exp) + def test_depth(self): + nested_tuple = (1, (2, (3, (4, (5, 6))))) + nested_dict = {1: {2: {3: {4: {5: {6: 6}}}}}} + nested_list = [1, [2, [3, [4, [5, [6, []]]]]]] + self.assertEqual(pprint.pformat(nested_tuple), repr(nested_tuple)) + self.assertEqual(pprint.pformat(nested_dict), repr(nested_dict)) + self.assertEqual(pprint.pformat(nested_list), repr(nested_list)) + lv1_tuple = '(1, (...))' + lv1_dict = '{1: {...}}' + lv1_list = '[1, [...]]' + self.assertEqual(pprint.pformat(nested_tuple, depth=1), lv1_tuple) + self.assertEqual(pprint.pformat(nested_dict, depth=1), lv1_dict) + self.assertEqual(pprint.pformat(nested_list, depth=1), lv1_list) + class DottedPrettyPrinter(pprint.PrettyPrinter): def format(self, object, context, maxlevels, level): Index: Doc/lib/libpprint.tex =================================================================== --- Doc/lib/libpprint.tex (revision 55224) +++ Doc/lib/libpprint.tex (working copy) @@ -67,12 +67,9 @@ '/usr/local/lib/python1.5/sharedmodules', '/usr/local/lib/python1.5/tkinter'] >>> ->>> import parser ->>> tup = parser.ast2tuple( -... parser.suite(open('pprint.py').read()))[1][1][1] ->>> pp = pprint.PrettyPrinter(depth=6) ->>> pp.pprint(tup) -(266, (267, (307, (287, (288, (...)))))) +>>> nested_tup = (1, (2, (3, (4, (5, (6)))))) +>>> pprint.pprint(nested_tup, depth=4) +(1, (2, (3, (4, (...))))) \end{verbatim} \end{classdesc}