]> granicus.if.org Git - python/commitdiff
Fixed issue #2888. Now the behaviour of pprint when working with nested
authorFacundo Batista <facundobatista@gmail.com>
Sat, 21 Jun 2008 17:43:56 +0000 (17:43 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Sat, 21 Jun 2008 17:43:56 +0000 (17:43 +0000)
structures follows the common sense (and works like in 2.5 and 3.0).

Doc/library/pprint.rst
Lib/pprint.py
Lib/test/test_pprint.py
Misc/NEWS

index c0bedf5d5b664ede23fae6be4ac93da245cd8afe..7bcb3f1856be1173f0d09bb9fa218777cc8cce42 100644 (file)
@@ -56,7 +56,7 @@ The :mod:`pprint` module defines one class:
       >>> stuff.insert(0, stuff[:])
       >>> pp = pprint.PrettyPrinter(indent=4)
       >>> pp.pprint(stuff)
-      [   [   'spam', 'eggs', 'lumberjack', 'knights', 'ni'],
+      [   ['spam', 'eggs', 'lumberjack', 'knights', 'ni'],
           'spam',
           'eggs',
           'lumberjack',
index 93d850aca18b1ffe4e102420e7c104d8de1a32c0..c48465b8d5855304de91697ef9065e4843bcdfa3 100644 (file)
@@ -194,7 +194,7 @@ class PrettyPrinter:
             else:
                 write('(')
                 endchar = ')'
-            if self._indent_per_level > 1:
+            if self._indent_per_level > 1 and sepLines:
                 write((self._indent_per_level - 1) * ' ')
             if length:
                 context[objid] = 1
index 4d7a3ed1472f160d8d534642966a6ac8501c540b..439f605e63ba7c2ca43edd2188c99acb0c32a340 100644 (file)
@@ -170,6 +170,17 @@ class QueryTestCase(unittest.TestCase):
         for type in [list, list2]:
             self.assertEqual(pprint.pformat(type(o), indent=4), exp)
 
+    def test_nested_indentations(self):
+        o1 = list(range(10))
+        o2 = dict(first=1, second=2, third=3)
+        o = [o1, o2]
+        expected = """\
+[   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
+    {   'first': 1,
+        'second': 2,
+        'third': 3}]"""
+        self.assertEqual(pprint.pformat(o, indent=4, width=42), expected)
+
     def test_sorted_dict(self):
         # Starting in Python 2.5, pprint sorts dict displays by key regardless
         # of how small the dictionary may be.
index 2825198169dfd425282ccc40b6748696a8bd6c7a..c5dfe73065f91f996ae4b047a072c1fe4eaa29ac 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -108,6 +108,10 @@ Extension Modules
 Library
 -------
 
+- Issue #2888: Fixed the behaviour of pprint when working with nested
+  structures, to match the behaviour of 2.5 and 3.0 (now follows the common
+  sense).
+
 - Issue #3136: fileConfig()'s disabling of old loggers is now conditional via
   an optional disable_existing_loggers parameter, but the default value is
   such that the old behaviour is preserved. Thanks to Leandro Lucarella for