diff options
author | Facundo Batista <facundobatista@gmail.com> | 2008-06-21 17:43:56 +0000 |
---|---|---|
committer | Facundo Batista <facundobatista@gmail.com> | 2008-06-21 17:43:56 +0000 |
commit | 2da91c375b095a452dd1e81962983e89e3fd0d07 (patch) | |
tree | 833230da7671d829dd39742984e524bf046eba10 /Lib | |
parent | 8e1c52ac0e551505f0edb4aad2774c37e1d93ea5 (diff) | |
download | cpython-git-2da91c375b095a452dd1e81962983e89e3fd0d07.tar.gz |
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).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pprint.py | 2 | ||||
-rw-r--r-- | Lib/test/test_pprint.py | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index 93d850aca1..c48465b8d5 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -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 diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 4d7a3ed147..439f605e63 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -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. |