Skip to content

Commit cfb5a76

Browse files
committed
Remove expand option, this is now the default
1 parent cce0ee4 commit cfb5a76

5 files changed

Lines changed: 237 additions & 394 deletions

File tree

Doc/library/pprint.rst

Lines changed: 15 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Functions
3131
---------
3232

3333
.. function:: pp(object, stream=None, indent=4, width=88, depth=None, *, \
34-
compact=False, expand=True, sort_dicts=False, \
35-
underscore_numbers=False)
34+
compact=False, sort_dicts=False, underscore_numbers=False)
3635

3736
Prints the formatted representation of *object*, followed by a newline.
3837
This function may be used in the interactive interpreter
@@ -66,22 +65,12 @@ Functions
6665

6766
:param bool compact:
6867
Control the way long :term:`sequences <sequence>` are formatted.
69-
If ``True``, as many items as will fit within the *width*
70-
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``.
76-
Takes precedence over *expand*.
77-
78-
:param bool expand:
79-
If ``True`` (the default),
68+
If ``False`` (the default),
8069
opening parentheses and brackets will be followed by a newline and the
8170
following content will be indented by one level, similar to
82-
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.
71+
pretty-printed JSON.
72+
If ``True``, as many items as will fit within the *width*
73+
will be formatted on each output line.
8574

8675
:param bool sort_dicts:
8776
If ``True``, dictionaries will be formatted with
@@ -103,20 +92,18 @@ Functions
10392

10493

10594
.. function:: pprint(object, stream=None, indent=4, width=88, depth=None, *, \
106-
compact=False, expand=True, sort_dicts=True, \
107-
underscore_numbers=False)
95+
compact=False, sort_dicts=True, underscore_numbers=False)
10896

10997
Alias for :func:`~pprint.pp` with *sort_dicts* set to ``True`` by default,
11098
which would automatically sort the dictionaries' keys,
11199
you might want to use :func:`~pprint.pp` instead where it is ``False`` by default.
112100

113101

114102
.. function:: pformat(object, indent=4, width=88, depth=None, *, \
115-
compact=False, expand=True, sort_dicts=True, \
116-
underscore_numbers=False)
103+
compact=False, sort_dicts=True, underscore_numbers=False)
117104

118105
Return the formatted representation of *object* as a string. *indent*,
119-
*width*, *depth*, *compact*, *expand*, *sort_dicts* and *underscore_numbers* are
106+
*width*, *depth*, *compact*, *sort_dicts* and *underscore_numbers* are
120107
passed to the :class:`PrettyPrinter` constructor as formatting parameters
121108
and their meanings are as described in the documentation above.
122109

@@ -160,7 +147,7 @@ PrettyPrinter objects
160147
.. index:: single: ...; placeholder
161148

162149
.. class:: PrettyPrinter(indent=4, width=88, depth=None, stream=None, *, \
163-
compact=False, expand=True, sort_dicts=True, \
150+
compact=False, sort_dicts=True, \
164151
underscore_numbers=False)
165152

166153
Construct a :class:`PrettyPrinter` instance.
@@ -181,7 +168,7 @@ PrettyPrinter objects
181168
'knights',
182169
'ni',
183170
]
184-
>>> pp = pprint.PrettyPrinter(indent=1, width=41, compact=True, expand=False)
171+
>>> pp = pprint.PrettyPrinter(indent=1, width=41, compact=True)
185172
>>> pp.pprint(stuff)
186173
[['spam', 'eggs', 'lumberjack',
187174
'knights', 'ni'],
@@ -222,14 +209,12 @@ PrettyPrinter objects
222209
.. versionchanged:: 3.11
223210
No longer attempts to write to :data:`!sys.stdout` if it is ``None``.
224211

225-
.. versionchanged:: 3.15
226-
Added the *expand* parameter.
227-
228212
.. versionchanged:: next
229-
Changed default *indent* from 1 to 4,
230-
default *width* from 80 to 88,
231-
and default *expand* from ``False`` to ``True``.
232-
*compact* takes precedence over *expand* when both are ``True``.
213+
Changed default *indent* from 1 to 4
214+
and default *width* from 80 to 88.
215+
The default ``compact=False`` layout is now similar to
216+
pretty-printed JSON, with opening parentheses and brackets
217+
followed by a newline and the contents indented by one level.
233218

234219

235220
:class:`PrettyPrinter` instances have the following methods:
@@ -447,60 +432,3 @@ cannot be split, the specified width will be exceeded::
447432
'summary': 'A sample Python project',
448433
'version': '1.2.0',
449434
}
450-
451-
The *expand* format (similar to pretty-printed JSON) is the default.
452-
To disable it, pass ``expand=False``::
453-
454-
>>> pprint.pp(project_info, expand=False)
455-
{ 'author': 'The Python Packaging Authority',
456-
'author_email': 'pypa-dev@googlegroups.com',
457-
'bugtrack_url': None,
458-
'classifiers': [ 'Development Status :: 3 - Alpha',
459-
'Intended Audience :: Developers',
460-
'License :: OSI Approved :: MIT License',
461-
'Programming Language :: Python :: 2',
462-
'Programming Language :: Python :: 2.6',
463-
'Programming Language :: Python :: 2.7',
464-
'Programming Language :: Python :: 3',
465-
'Programming Language :: Python :: 3.2',
466-
'Programming Language :: Python :: 3.3',
467-
'Programming Language :: Python :: 3.4',
468-
'Topic :: Software Development :: Build Tools'],
469-
'description': 'A sample Python project\n'
470-
'=======================\n'
471-
'\n'
472-
'This is the description file for the project.\n'
473-
'\n'
474-
'The file should use UTF-8 encoding and be written using '
475-
'ReStructured Text. It\n'
476-
'will be used to generate the project webpage on PyPI, and should '
477-
'be written for\n'
478-
'that purpose.\n'
479-
'\n'
480-
'Typical contents for this file would include an overview of the '
481-
'project, basic\n'
482-
'usage examples, etc. Generally, including the project changelog in '
483-
'here is not\n'
484-
'a good idea, although a simple "What\'s New" section for the most '
485-
'recent version\n'
486-
'may be appropriate.',
487-
'description_content_type': None,
488-
'docs_url': None,
489-
'download_url': 'UNKNOWN',
490-
'downloads': {'last_day': -1, 'last_month': -1, 'last_week': -1},
491-
'home_page': 'https://github.com/pypa/sampleproject',
492-
'keywords': 'sample setuptools development',
493-
'license': 'MIT',
494-
'maintainer': None,
495-
'maintainer_email': None,
496-
'name': 'sampleproject',
497-
'package_url': 'https://pypi.org/project/sampleproject/',
498-
'platform': 'UNKNOWN',
499-
'project_url': 'https://pypi.org/project/sampleproject/',
500-
'project_urls': { 'Download': 'UNKNOWN',
501-
'Homepage': 'https://github.com/pypa/sampleproject'},
502-
'release_url': 'https://pypi.org/project/sampleproject/1.2.0/',
503-
'requires_dist': None,
504-
'requires_python': None,
505-
'summary': 'A sample Python project',
506-
'version': '1.2.0'}

Doc/whatsnew/3.15.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,16 +1087,11 @@ pickletools
10871087
pprint
10881088
------
10891089

1090-
* Add an *expand* keyword argument for :func:`pprint.pprint`,
1091-
:func:`pprint.pformat`, :func:`pprint.pp`. If true, the output will be
1092-
formatted similar to pretty-printed :func:`json.dumps` when
1093-
*indent* is supplied.
1090+
* :mod:`pprint` now uses modern defaults: ``indent=4, width=88``,
1091+
and the default ``compact=False`` output is now formatted similar to
1092+
pretty-printed :func:`json.dumps`.
10941093
(Contributed by Stefan Todoran, Semyon Moroz and Hugo van Kemenade in
1095-
:gh:`112632`.)
1096-
1097-
* :mod:`pprint` now uses modern defaults: ``indent=4, width=88, expand=True``.
1098-
Use ``indent=1, width=80, expand=False`` to retain old output.
1099-
(Contributed by Hugo van Kemenade in :gh:`149189`.)
1094+
:gh:`112632` and :gh:`149189`.)
11001095

11011096
* Add t-string support to :mod:`pprint`.
11021097
(Contributed by Loïc Simon and Hugo van Kemenade in :gh:`134551`.)

0 commit comments

Comments
 (0)