From 394fe0f88e71066ec0ac33c06be387755350e8e0 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov <39376984+Privat33r-dev@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:36:22 +0100 Subject: [PATCH 1/4] Docs: promote pprint.pp usage as a default --- Doc/library/pprint.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index 32e1351b7ffeeb..204a3154d9dc4d 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -61,6 +61,9 @@ Functions :class:`PrettyPrinter` constructor and their meanings are as described in its documentation below. + Note that *sort_dicts* default is ``True`` and you might want to use + :func:`~pprint.pp` instead.:: + >>> import pprint >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] >>> stuff.insert(0, stuff) @@ -261,7 +264,7 @@ are converted to strings. The default implementation uses the internals of the Example ------- -To demonstrate several uses of the :func:`~pprint.pprint` function and its parameters, +To demonstrate several uses of the :func:`~pprint.pp` function and its parameters, let's fetch information about a project from `PyPI `_:: >>> import json @@ -270,9 +273,9 @@ let's fetch information about a project from `PyPI `_:: >>> with urlopen('https://pypi.org/pypi/sampleproject/json') as resp: ... project_info = json.load(resp)['info'] -In its basic form, :func:`~pprint.pprint` shows the whole object:: +In its basic form, :func:`~pprint.pp` shows the whole object:: - >>> pprint.pprint(project_info) + >>> pprint.pp(project_info) {'author': 'The Python Packaging Authority', 'author_email': 'pypa-dev@googlegroups.com', 'bugtrack_url': None, @@ -329,7 +332,7 @@ In its basic form, :func:`~pprint.pprint` shows the whole object:: The result can be limited to a certain *depth* (ellipsis is used for deeper contents):: - >>> pprint.pprint(project_info, depth=1) + >>> pprint.pp(project_info, depth=1) {'author': 'The Python Packaging Authority', 'author_email': 'pypa-dev@googlegroups.com', 'bugtrack_url': None, @@ -375,7 +378,7 @@ contents):: Additionally, maximum character *width* can be suggested. If a long object cannot be split, the specified width will be exceeded:: - >>> pprint.pprint(project_info, depth=1, width=60) + >>> pprint.pp(project_info, depth=1, width=60) {'author': 'The Python Packaging Authority', 'author_email': 'pypa-dev@googlegroups.com', 'bugtrack_url': None, From 6bc4a6f07b6724aa189efee69dd0322b27639b7c Mon Sep 17 00:00:00 2001 From: Kerim Kabirov <39376984+Privat33r-dev@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:54:31 +0100 Subject: [PATCH 2/4] fix tests, move example --- Doc/library/pprint.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index 204a3154d9dc4d..cc6f8b95a5ee10 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -44,6 +44,17 @@ Functions *args* and *kwargs* will be passed to :func:`~pprint.pprint` as formatting parameters. + >>> import pprint + >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] + >>> stuff.insert(0, stuff) + >>> pprint.pprint(stuff) + [, + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] + .. versionadded:: 3.8 @@ -62,18 +73,7 @@ Functions described in its documentation below. Note that *sort_dicts* default is ``True`` and you might want to use - :func:`~pprint.pp` instead.:: - - >>> import pprint - >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> stuff.insert(0, stuff) - >>> pprint.pprint(stuff) - [, - 'spam', - 'eggs', - 'lumberjack', - 'knights', - 'ni'] + :func:`~pprint.pp` instead. .. function:: pformat(object, indent=1, width=80, depth=None, *, \ compact=False, sort_dicts=True, underscore_numbers=False) From 9a78e6ee50550200a4e7e90254e4b5e362b59bde Mon Sep 17 00:00:00 2001 From: Kerim Kabirov <39376984+Privat33r-dev@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:55:47 +0100 Subject: [PATCH 3/4] fix example --- Doc/library/pprint.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index cc6f8b95a5ee10..1cd281154edd23 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -47,7 +47,7 @@ Functions >>> import pprint >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] >>> stuff.insert(0, stuff) - >>> pprint.pprint(stuff) + >>> pprint.pp(stuff) [, 'spam', 'eggs', From 16252cde53b558e2019d5bbf7eb5f426a0e9c983 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Tue, 19 Mar 2024 22:32:03 +0100 Subject: [PATCH 4/4] Make 'pprint.pp's suggestion conciser Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/pprint.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index 1cd281154edd23..eebd270a096ba5 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -72,8 +72,8 @@ Functions :class:`PrettyPrinter` constructor and their meanings are as described in its documentation below. - Note that *sort_dicts* default is ``True`` and you might want to use - :func:`~pprint.pp` instead. + Note that *sort_dicts* is ``True`` by default and you might want to use + :func:`~pprint.pp` instead where it is ``False`` by default. .. function:: pformat(object, indent=1, width=80, depth=None, *, \ compact=False, sort_dicts=True, underscore_numbers=False)