Skip to content

Commit a7707f9

Browse files
committed
Default pprint to expand=True indent=4 width=88
1 parent eb2f634 commit a7707f9

6 files changed

Lines changed: 316 additions & 285 deletions

File tree

Lib/difflib.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,17 @@ def get_grouped_opcodes(self, n=3):
559559
>>> b[23:28] = [] # Make a deletion
560560
>>> b[30] += 'y' # Make another replacement
561561
>>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
562-
[[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
563-
[('equal', 16, 19, 17, 20),
564-
('replace', 19, 20, 20, 21),
565-
('equal', 20, 22, 21, 23),
566-
('delete', 22, 27, 23, 23),
567-
('equal', 27, 30, 23, 26)],
568-
[('equal', 31, 34, 27, 30),
569-
('replace', 34, 35, 30, 31),
570-
('equal', 35, 38, 31, 34)]]
562+
[
563+
[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
564+
[
565+
('equal', 16, 19, 17, 20),
566+
('replace', 19, 20, 20, 21),
567+
('equal', 20, 22, 21, 23),
568+
('delete', 22, 27, 23, 23),
569+
('equal', 27, 30, 23, 26),
570+
],
571+
[('equal', 31, 34, 27, 30), ('replace', 34, 35, 30, 31), ('equal', 35, 38, 31, 34)],
572+
]
571573
"""
572574

573575
codes = self.get_opcodes()
@@ -784,16 +786,18 @@ class Differ:
784786
785787
>>> from pprint import pprint as _pprint
786788
>>> _pprint(result)
787-
[' 1. Beautiful is better than ugly.\n',
788-
'- 2. Explicit is better than implicit.\n',
789-
'- 3. Simple is better than complex.\n',
790-
'+ 3. Simple is better than complex.\n',
791-
'? ++\n',
792-
'- 4. Complex is better than complicated.\n',
793-
'? ^ ---- ^\n',
794-
'+ 4. Complicated is better than complex.\n',
795-
'? ++++ ^ ^\n',
796-
'+ 5. Flat is better than nested.\n']
789+
[
790+
' 1. Beautiful is better than ugly.\n',
791+
'- 2. Explicit is better than implicit.\n',
792+
'- 3. Simple is better than complex.\n',
793+
'+ 3. Simple is better than complex.\n',
794+
'? ++\n',
795+
'- 4. Complex is better than complicated.\n',
796+
'? ^ ---- ^\n',
797+
'+ 4. Complicated is better than complex.\n',
798+
'? ++++ ^ ^\n',
799+
'+ 5. Flat is better than nested.\n',
800+
]
797801
798802
As a single multi-line string it looks like this:
799803

Lib/pprint.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@
4343
"PrettyPrinter", "pp"]
4444

4545

46-
def pprint(object, stream=None, indent=1, width=80, depth=None, *,
47-
compact=False, expand=False, sort_dicts=True,
48-
underscore_numbers=False):
46+
def pprint(
47+
object,
48+
stream=None,
49+
indent=4,
50+
width=88,
51+
depth=None,
52+
*,
53+
compact=False,
54+
expand=True,
55+
sort_dicts=True,
56+
underscore_numbers=False,
57+
):
4958
"""Pretty-print a Python object to a stream [default is sys.stdout]."""
5059
printer = PrettyPrinter(
5160
stream=stream, indent=indent, width=width, depth=depth,
@@ -54,9 +63,17 @@ def pprint(object, stream=None, indent=1, width=80, depth=None, *,
5463
printer.pprint(object)
5564

5665

57-
def pformat(object, indent=1, width=80, depth=None, *,
58-
compact=False, expand=False, sort_dicts=True,
59-
underscore_numbers=False):
66+
def pformat(
67+
object,
68+
indent=4,
69+
width=88,
70+
depth=None,
71+
*,
72+
compact=False,
73+
expand=True,
74+
sort_dicts=True,
75+
underscore_numbers=False,
76+
):
6077
"""Format a Python object into a pretty-printed representation."""
6178
return PrettyPrinter(indent=indent, width=width, depth=depth,
6279
compact=compact, expand=expand, sort_dicts=sort_dicts,
@@ -112,9 +129,18 @@ def _safe_tuple(t):
112129

113130

114131
class PrettyPrinter:
115-
def __init__(self, indent=1, width=80, depth=None, stream=None, *,
116-
compact=False, expand=False, sort_dicts=True,
117-
underscore_numbers=False):
132+
def __init__(
133+
self,
134+
indent=4,
135+
width=88,
136+
depth=None,
137+
stream=None,
138+
*,
139+
compact=False,
140+
expand=True,
141+
sort_dicts=True,
142+
underscore_numbers=False,
143+
):
118144
"""Handle pretty printing operations onto a stream using a set of
119145
configured parameters.
120146

Lib/test/test_descrtut.py

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -168,54 +168,56 @@ def merge(self, other):
168168
169169
>>> import pprint
170170
>>> pprint.pprint(dir(list)) # like list.__dict__.keys(), but sorted
171-
['__add__',
172-
'__class__',
173-
'__class_getitem__',
174-
'__contains__',
175-
'__delattr__',
176-
'__delitem__',
177-
'__dir__',
178-
'__doc__',
179-
'__eq__',
180-
'__format__',
181-
'__ge__',
182-
'__getattribute__',
183-
'__getitem__',
184-
'__getstate__',
185-
'__gt__',
186-
'__hash__',
187-
'__iadd__',
188-
'__imul__',
189-
'__init__',
190-
'__init_subclass__',
191-
'__iter__',
192-
'__le__',
193-
'__len__',
194-
'__lt__',
195-
'__mul__',
196-
'__ne__',
197-
'__new__',
198-
'__reduce__',
199-
'__reduce_ex__',
200-
'__repr__',
201-
'__reversed__',
202-
'__rmul__',
203-
'__setattr__',
204-
'__setitem__',
205-
'__sizeof__',
206-
'__str__',
207-
'__subclasshook__',
208-
'append',
209-
'clear',
210-
'copy',
211-
'count',
212-
'extend',
213-
'index',
214-
'insert',
215-
'pop',
216-
'remove',
217-
'reverse',
218-
'sort']
171+
[
172+
'__add__',
173+
'__class__',
174+
'__class_getitem__',
175+
'__contains__',
176+
'__delattr__',
177+
'__delitem__',
178+
'__dir__',
179+
'__doc__',
180+
'__eq__',
181+
'__format__',
182+
'__ge__',
183+
'__getattribute__',
184+
'__getitem__',
185+
'__getstate__',
186+
'__gt__',
187+
'__hash__',
188+
'__iadd__',
189+
'__imul__',
190+
'__init__',
191+
'__init_subclass__',
192+
'__iter__',
193+
'__le__',
194+
'__len__',
195+
'__lt__',
196+
'__mul__',
197+
'__ne__',
198+
'__new__',
199+
'__reduce__',
200+
'__reduce_ex__',
201+
'__repr__',
202+
'__reversed__',
203+
'__rmul__',
204+
'__setattr__',
205+
'__setitem__',
206+
'__sizeof__',
207+
'__str__',
208+
'__subclasshook__',
209+
'append',
210+
'clear',
211+
'copy',
212+
'count',
213+
'extend',
214+
'index',
215+
'insert',
216+
'pop',
217+
'remove',
218+
'reverse',
219+
'sort',
220+
]
219221
220222
The new introspection API gives more information than the old one: in
221223
addition to the regular methods, it also shows the methods that are

Lib/test/test_pickle.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -786,11 +786,7 @@ def test_invocation(self):
786786
'b': ('character string', b'byte string'),
787787
'c': 'string'
788788
}
789-
expect = '''
790-
{'a': [1, 2.0, (3+4j)],
791-
'b': ('character string', b'byte string'),
792-
'c': 'string'}
793-
'''
789+
expect = "{'a': [1, 2.0, (3+4j)], 'b': ('character string', b'byte string'), 'c': 'string'}"
794790
self.set_pickle_data(data)
795791

796792
with self.subTest(data=data):

0 commit comments

Comments
 (0)