-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-41546: make pprint (like print) not write to stdout when it is None #26810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
69741ec
793fba5
214fb4f
be4404e
db4e471
62af033
fba7e43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ The :mod:`pprint` module defines one class: | |
|
||
*stream* (default ``sys.stdout``) is a :term:`file-like object` to | ||
which the output will be written by calling its :meth:`write` method. | ||
If both *stream* and ``sys.stdout`` are ``None``, then | ||
:meth:`~PrettyPrinter.pprint` silently returns. | ||
|
||
Other values configure the manner in which nesting of complex data | ||
structures is displayed. | ||
|
@@ -84,6 +86,9 @@ The :mod:`pprint` module defines one class: | |
.. versionchanged:: 3.10 | ||
Added the *underscore_numbers* parameter. | ||
|
||
.. versionchanged:: 3.11 | ||
No longer attempts to write to ``sys.stdout`` if it is None. | ||
|
||
>>> import pprint | ||
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] | ||
>>> stuff.insert(0, stuff[:]) | ||
|
@@ -107,24 +112,13 @@ The :mod:`pprint` module defines one class: | |
>>> pp.pprint(tup) | ||
('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) | ||
|
||
|
||
The :mod:`pprint` module also provides several shortcut functions: | ||
|
||
.. function:: pformat(object, indent=1, width=80, depth=None, *, \ | ||
compact=False, sort_dicts=True, underscore_numbers=False) | ||
|
||
Return the formatted representation of *object* as a string. *indent*, | ||
*width*, *depth*, *compact*, *sort_dicts* and *underscore_numbers* will be passed to the | ||
:class:`PrettyPrinter` constructor as formatting parameters. | ||
|
||
.. versionchanged:: 3.4 | ||
Added the *compact* parameter. | ||
|
||
.. versionchanged:: 3.8 | ||
Added the *sort_dicts* parameter. | ||
|
||
.. versionchanged:: 3.10 | ||
Added the *underscore_numbers* parameter. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove versionchanged notes? People need to know this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're removing the repetitions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But these are not needless repetitions: they are separate notes on separate functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We removed repetition not only of the version labels but also of the definitions they relate to, and we replaced them by a reference to where those definitions appear (once). It is easier read the docs when they are not repetitive because then you know that A is the same as B, and you don't need to do the work to compare them just to find that out. |
||
*width*, *depth*, *compact*, *sort_dicts* and *underscore_numbers* are | ||
passed to the :class:`PrettyPrinter` constructor as formatting parameters | ||
and their meanings are as described in its documentation above. | ||
|
||
|
||
.. function:: pp(object, *args, sort_dicts=False, **kwargs) | ||
|
@@ -142,20 +136,15 @@ The :mod:`pprint` module also provides several shortcut functions: | |
compact=False, sort_dicts=True, underscore_numbers=False) | ||
|
||
Prints the formatted representation of *object* on *stream*, followed by a | ||
newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used | ||
newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used | ||
in the interactive interpreter instead of the :func:`print` function for | ||
inspecting values (you can even reassign ``print = pprint.pprint`` for use | ||
within a scope). *indent*, *width*, *depth*, *compact*, *sort_dicts* and *underscore_numbers* will | ||
be passed to the :class:`PrettyPrinter` constructor as formatting parameters. | ||
|
||
.. versionchanged:: 3.4 | ||
Added the *compact* parameter. | ||
|
||
.. versionchanged:: 3.8 | ||
Added the *sort_dicts* parameter. | ||
within a scope). | ||
|
||
.. versionchanged:: 3.10 | ||
Added the *underscore_numbers* parameter. | ||
The configuration parameters *stream*, *indent*, *width*, *depth*, | ||
*compact*, *sort_dicts* and *underscore_numbers* are passed to the | ||
:class:`PrettyPrinter` constructor and their meanings are as | ||
described in its documentation above. | ||
|
||
>>> import pprint | ||
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] | ||
|
@@ -168,7 +157,6 @@ The :mod:`pprint` module also provides several shortcut functions: | |
'knights', | ||
'ni'] | ||
|
||
|
||
.. function:: isreadable(object) | ||
|
||
.. index:: builtin: eval | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Make :mod:`pprint` (like the builtin ``print``) not attempt to write to ``stdout`` when it is ``None``. |
Uh oh!
There was an error while loading. Please reload this page.