Skip to content

Commit cce0ee4

Browse files
committed
Add note about compact=False
1 parent 3c5d8f4 commit cce0ee4

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Doc/library/pprint.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,22 @@ Functions
6666

6767
:param bool compact:
6868
Control the way long :term:`sequences <sequence>` are formatted.
69-
If ``False`` (the default),
70-
each item of a sequence will be formatted on a separate line,
71-
otherwise as many items as will fit within the *width*
69+
If ``True``, as many items as will fit within the *width*
7270
will be formatted on each output line.
71+
If ``False`` (the default), each item of a sequence
72+
will be formatted on a separate line,
73+
*unless* *expand* mode is also active (which is now the default);
74+
to opt out of *expand* mode, pass ``expand=False`` rather than
75+
relying on ``compact=False``.
7376
Takes precedence over *expand*.
7477

7578
:param bool expand:
7679
If ``True`` (the default),
7780
opening parentheses and brackets will be followed by a newline and the
7881
following content will be indented by one level, similar to
7982
pretty-printed JSON. Has no effect when *compact* is also ``True``.
83+
Pass ``expand=False`` to restore the pre-3.15 layout where each
84+
item appears on its own line without the extra indentation.
8085

8186
:param bool sort_dicts:
8287
If ``True``, dictionaries will be formatted with

Lib/pprint.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,12 @@ def __init__(
159159
160160
compact
161161
If true, several items will be combined in one line.
162-
Takes precedence over expand mode.
162+
Takes precedence over expand mode. The default (false) no longer
163+
disables expand mode on its own; pass ``expand=False`` for that.
163164
164165
expand
165-
If true, the output will be formatted similar to
166-
pretty-printed json.dumps() when ``indent`` is supplied.
166+
If true (the default), the output will be formatted similar
167+
to pretty-printed json.dumps() when ``indent`` is supplied.
167168
Has no effect if compact mode is also enabled.
168169
169170
sort_dicts

0 commit comments

Comments
 (0)