[Python-checkins] r64446 - in python/trunk: Doc/library/pprint.rst Lib/pprint.py Lib/test/test_pprint.py Misc/NEWS

facundo.batista python-checkins at python.org
Sat Jun 21 19:43:56 CEST 2008


Author: facundo.batista
Date: Sat Jun 21 19:43:56 2008
New Revision: 64446
Log:
Fixed issue #2888. Now the behaviour of pprint when working with nested
structures follows the common sense (and works like in 2.5 and 3.0).
Modified:
 python/trunk/Doc/library/pprint.rst
 python/trunk/Lib/pprint.py
 python/trunk/Lib/test/test_pprint.py
 python/trunk/Misc/NEWS
Modified: python/trunk/Doc/library/pprint.rst
==============================================================================
--- python/trunk/Doc/library/pprint.rst	(original)
+++ python/trunk/Doc/library/pprint.rst	Sat Jun 21 19:43:56 2008
@@ -56,7 +56,7 @@
 >>> 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',
Modified: python/trunk/Lib/pprint.py
==============================================================================
--- python/trunk/Lib/pprint.py	(original)
+++ python/trunk/Lib/pprint.py	Sat Jun 21 19:43:56 2008
@@ -194,7 +194,7 @@
 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
Modified: python/trunk/Lib/test/test_pprint.py
==============================================================================
--- python/trunk/Lib/test/test_pprint.py	(original)
+++ python/trunk/Lib/test/test_pprint.py	Sat Jun 21 19:43:56 2008
@@ -170,6 +170,17 @@
 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.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Jun 21 19:43:56 2008
@@ -108,6 +108,10 @@
 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


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /