From cc92c08f7fa33376ab5ff15ea65edc7da4e474eb Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Sun, 31 Mar 2024 13:44:03 +0200 Subject: [PATCH 1/8] Move pprinter parameters description to the table The change improves readability. Suggested in the GH#116085 PR discussion. --- Doc/library/pprint.rst | 82 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index eebd270a096ba5..f85b46c6aeca45 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -70,18 +70,57 @@ Functions 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 below. + described in the documentation below. Note that *sort_dicts* is ``True`` by default and you might want to use :func:`~pprint.pp` instead where it is ``False`` by default. +.. _prettyprinter-parameters: + +.. list-table:: **Recognised parameters for PrettyPrinter** + :header-rows: 1 + :widths: 20 80 + + * - Parameter + - Description + * - ``indent``: ``int`` + - The amount of indentation added for each nesting level. + * - ``width``: ``int`` + - The desired maximum number of characters per line in the output. + If a structure cannot be formatted within the width constraint, + a best effort will be made. + * - ``depth``: ``int`` | ``None`` + - The number of nesting levels which may be printed. + If the data structure being printed is too deep, + the next contained level is replaced by ``...``. + If ``None`` (the default), there is no constraint + on the depth of the objects being formatted. + * - ``stream``: :term:`file-like object` | ``None`` + - A file-like object to which the output will be written + by calling its :meth:`!write` method. + If ``None`` (the default), :data:`sys.stdout` is used. + * - ``compact``: ``bool`` + - Control the way long :term:`sequences ` are formatted. + If ``False`` (the default), + each item of a sequence will be formatted on a separate line, + otherwise as many items as will fit within the *width* + will be formatted on each output line. + * - ``sort_dicts``: ``bool`` + - If ``True`` (the default), dictionaries will be formatted with + their keys sorted, otherwise they will display in insertion order. + * - ``underscore_numbers``: ``bool`` + - If ``True``, + integers will be formatted with the ``_`` character for a thousands separator, + otherwise underscores are not displayed (the default). + + .. 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* are passed to the :class:`PrettyPrinter` constructor as formatting parameters - and their meanings are as described in its documentation below. + and their meanings are as described in the documentation above. .. function:: isreadable(object) @@ -120,11 +159,6 @@ Functions PrettyPrinter Objects --------------------- -This module defines one class: - -.. First the implementation class: - - .. index:: single: ...; placeholder .. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, \ @@ -132,39 +166,7 @@ This module defines one class: Construct a :class:`PrettyPrinter` instance. This constructor understands several keyword parameters. - - *stream* (default :data:`!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 :data:`!sys.stdout` are ``None``, then - :meth:`~PrettyPrinter.pprint` silently returns. - - Other values configure the manner in which nesting of complex data - structures is displayed. - - *indent* (default 1) specifies the amount of indentation added for - each nesting level. - - *depth* controls the number of nesting levels which may be printed; if - the data structure being printed is too deep, the next contained level - is replaced by ``...``. By default, there is no constraint on the - depth of the objects being formatted. - - *width* (default 80) specifies the desired maximum number of characters per - line in the output. If a structure cannot be formatted within the width - constraint, a best effort will be made. - - *compact* impacts the way that long sequences (lists, tuples, sets, etc) - are formatted. If *compact* is false (the default) then each item of a - sequence will be formatted on a separate line. If *compact* is true, as - many items as will fit within the *width* will be formatted on each output - line. - - If *sort_dicts* is true (the default), dictionaries will be formatted with - their keys sorted, otherwise they will display in insertion order. - - If *underscore_numbers* is true, integers will be formatted with the - ``_`` character for a thousands separator, otherwise underscores are not - displayed (the default). + Parameters described at :ref:`parameters table `. .. versionchanged:: 3.4 Added the *compact* parameter. From 579785861e12903561a142e83b9383e6073fa9b2 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Tue, 30 Apr 2024 16:32:51 +0200 Subject: [PATCH 2/8] Make pprint doc with params markup --- Doc/library/pprint.rst | 152 ++++++++++++++++++++++++----------------- 1 file changed, 91 insertions(+), 61 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index f85b46c6aeca45..bbc976eee1ed44 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -36,13 +36,55 @@ Dictionaries are sorted by key before the display is computed. Functions --------- -.. function:: pp(object, *args, sort_dicts=False, **kwargs) - - Prints the formatted representation of *object* followed by a newline. - If *sort_dicts* is false (the default), dictionaries will be displayed with - their keys in insertion order, otherwise the dict keys will be sorted. - *args* and *kwargs* will be passed to :func:`~pprint.pprint` as formatting - parameters. +.. function:: pp(object, stream=None, indent=1, width=80, depth=None, *, \ + compact=False, sort_dicts=False, underscore_numbers=False) + + Prints the formatted representation of *object*, followed by a newline. + This function may be used in the interactive interpreter + instead of the :func:`print` function for inspecting values. + Tip: you can reassign ``print = pprint.pp`` for use within a scope. + + :param object: + The object to be printed. + + :param int indent: + The amount of indentation added for each nesting level. + + :param int width: + The desired maximum number of characters per line in the output. + If a structure cannot be formatted within the width constraint, + a best effort will be made. + + :param depth: + The number of nesting levels which may be printed. + If the data structure being printed is too deep, + the next contained level is replaced by ``...``. + If ``None`` (the default), there is no constraint + on the depth of the objects being formatted. + :type depth: int | None + + :param stream: + A file-like object to which the output will be written + by calling its :meth:`!write` method. + If ``None`` (the default), :data:`sys.stdout` is used. + :type stream: :term:`file-like object` | None + + :param bool compact: + Control the way long :term:`sequences ` are formatted. + If ``False`` (the default), + each item of a sequence will be formatted on a separate line, + otherwise as many items as will fit within the *width* + will be formatted on each output line. + + :param bool sort_dicts: + If ``True``, dictionaries will be formatted with + their keys sorted, otherwise + they will be displayed in insertion order (the default). + + :param bool underscore_numbers: + If ``True``, + integers will be formatted with the ``_`` character for a thousands separator, + otherwise underscores are not displayed (the default). >>> import pprint >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] @@ -61,57 +103,9 @@ Functions .. function:: pprint(object, stream=None, indent=1, width=80, depth=None, *, \ compact=False, sort_dicts=True, underscore_numbers=False) - Prints the formatted representation of *object* on *stream*, followed by a - newline. If *stream* is ``None``, :data:`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). - - 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 the documentation below. - - Note that *sort_dicts* is ``True`` by default and you might want to use - :func:`~pprint.pp` instead where it is ``False`` by default. - -.. _prettyprinter-parameters: - -.. list-table:: **Recognised parameters for PrettyPrinter** - :header-rows: 1 - :widths: 20 80 - - * - Parameter - - Description - * - ``indent``: ``int`` - - The amount of indentation added for each nesting level. - * - ``width``: ``int`` - - The desired maximum number of characters per line in the output. - If a structure cannot be formatted within the width constraint, - a best effort will be made. - * - ``depth``: ``int`` | ``None`` - - The number of nesting levels which may be printed. - If the data structure being printed is too deep, - the next contained level is replaced by ``...``. - If ``None`` (the default), there is no constraint - on the depth of the objects being formatted. - * - ``stream``: :term:`file-like object` | ``None`` - - A file-like object to which the output will be written - by calling its :meth:`!write` method. - If ``None`` (the default), :data:`sys.stdout` is used. - * - ``compact``: ``bool`` - - Control the way long :term:`sequences ` are formatted. - If ``False`` (the default), - each item of a sequence will be formatted on a separate line, - otherwise as many items as will fit within the *width* - will be formatted on each output line. - * - ``sort_dicts``: ``bool`` - - If ``True`` (the default), dictionaries will be formatted with - their keys sorted, otherwise they will display in insertion order. - * - ``underscore_numbers``: ``bool`` - - If ``True``, - integers will be formatted with the ``_`` character for a thousands separator, - otherwise underscores are not displayed (the default). + Alias for :func:`~pprint.pp` with *sort_dicts* set to ``True`` by default, + which would automatically sort the dictionaries' keys, + you might want to use :func:`~pprint.pp` instead where it is ``False`` by default. .. function:: pformat(object, indent=1, width=80, depth=None, *, \ @@ -164,9 +158,45 @@ PrettyPrinter Objects .. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, \ compact=False, sort_dicts=True, underscore_numbers=False) - Construct a :class:`PrettyPrinter` instance. This constructor understands - several keyword parameters. - Parameters described at :ref:`parameters table `. + Construct a :class:`PrettyPrinter` instance. + + :param int indent: + The amount of indentation added for each nesting level. + + :param int width: + The desired maximum number of characters per line in the output. + If a structure cannot be formatted within the width constraint, + a best effort will be made. + + :param depth: + The number of nesting levels which may be printed. + If the data structure being printed is too deep, + the next contained level is replaced by ``...``. + If ``None`` (the default), there is no constraint + on the depth of the objects being formatted. + :type depth: int | None + + :param stream: + A file-like object to which the output will be written + by calling its :meth:`!write` method. + If ``None`` (the default), :data:`sys.stdout` is used. + :type stream: :term:`file-like object` | None + + :param bool compact: + Control the way long :term:`sequences ` are formatted. + If ``False`` (the default), + each item of a sequence will be formatted on a separate line, + otherwise as many items as will fit within the *width* + will be formatted on each output line. + + :param bool sort_dicts: + If ``True`` (the default), dictionaries will be formatted with + their keys sorted, otherwise they will be displayed in insertion order. + + :param bool underscore_numbers: + If ``True``, + integers will be formatted with the ``_`` character for a thousands separator, + otherwise underscores are not displayed (the default). .. versionchanged:: 3.4 Added the *compact* parameter. From e6147224af9caaf75bc2cd0013a10699c79051b3 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Thu, 2 May 2024 10:12:06 +0200 Subject: [PATCH 3/8] Fix formatting Indentation of code blocks made them nested "Version changed" is better placed after the code block --- Doc/library/pprint.rst | 67 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index bbc976eee1ed44..06a875d57cb519 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -86,16 +86,16 @@ Functions integers will be formatted with the ``_`` character for a thousands separator, otherwise underscores are not displayed (the default). - >>> import pprint - >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> stuff.insert(0, stuff) - >>> pprint.pp(stuff) - [, - 'spam', - 'eggs', - 'lumberjack', - 'knights', - 'ni'] + >>> import pprint + >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] + >>> stuff.insert(0, stuff) + >>> pprint.pp(stuff) + [, + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] .. versionadded:: 3.8 @@ -198,6 +198,30 @@ PrettyPrinter Objects integers will be formatted with the ``_`` character for a thousands separator, otherwise underscores are not displayed (the default). + >>> import pprint + >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] + >>> stuff.insert(0, stuff[:]) + >>> pp = pprint.PrettyPrinter(indent=4) + >>> pp.pprint(stuff) + [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] + >>> pp = pprint.PrettyPrinter(width=41, compact=True) + >>> pp.pprint(stuff) + [['spam', 'eggs', 'lumberjack', + 'knights', 'ni'], + 'spam', 'eggs', 'lumberjack', 'knights', + 'ni'] + >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', + ... ('parrot', ('fresh fruit',)))))))) + >>> pp = pprint.PrettyPrinter(depth=6) + >>> pp.pprint(tup) + ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) + + .. versionchanged:: 3.4 Added the *compact* parameter. @@ -210,29 +234,6 @@ PrettyPrinter Objects .. versionchanged:: 3.11 No longer attempts to write to :data:`!sys.stdout` if it is ``None``. - >>> import pprint - >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> stuff.insert(0, stuff[:]) - >>> pp = pprint.PrettyPrinter(indent=4) - >>> pp.pprint(stuff) - [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], - 'spam', - 'eggs', - 'lumberjack', - 'knights', - 'ni'] - >>> pp = pprint.PrettyPrinter(width=41, compact=True) - >>> pp.pprint(stuff) - [['spam', 'eggs', 'lumberjack', - 'knights', 'ni'], - 'spam', 'eggs', 'lumberjack', 'knights', - 'ni'] - >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', - ... ('parrot', ('fresh fruit',)))))))) - >>> pp = pprint.PrettyPrinter(depth=6) - >>> pp.pprint(tup) - ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) - :class:`PrettyPrinter` instances have the following methods: From ebcafbf135de4deba7790aa05980ea222f2b1f00 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Thu, 2 May 2024 11:57:34 +0200 Subject: [PATCH 4/8] Fix formatting for tests --- Doc/library/pprint.rst | 66 ++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index 06a875d57cb519..209874d9c6a0d1 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -86,16 +86,18 @@ Functions integers will be formatted with the ``_`` character for a thousands separator, otherwise underscores are not displayed (the default). - >>> import pprint - >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> stuff.insert(0, stuff) - >>> pprint.pp(stuff) - [, - 'spam', - 'eggs', - 'lumberjack', - 'knights', - 'ni'] + Usage example: + + >>> import pprint + >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] + >>> stuff.insert(0, stuff) + >>> pprint.pp(stuff) + [, + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] .. versionadded:: 3.8 @@ -198,28 +200,30 @@ PrettyPrinter Objects integers will be formatted with the ``_`` character for a thousands separator, otherwise underscores are not displayed (the default). - >>> import pprint - >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> stuff.insert(0, stuff[:]) - >>> pp = pprint.PrettyPrinter(indent=4) - >>> pp.pprint(stuff) - [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], - 'spam', - 'eggs', - 'lumberjack', - 'knights', + Usage example: + + >>> import pprint + >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] + >>> stuff.insert(0, stuff[:]) + >>> pp = pprint.PrettyPrinter(indent=4) + >>> pp.pprint(stuff) + [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] + >>> pp = pprint.PrettyPrinter(width=41, compact=True) + >>> pp.pprint(stuff) + [['spam', 'eggs', 'lumberjack', + 'knights', 'ni'], + 'spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> pp = pprint.PrettyPrinter(width=41, compact=True) - >>> pp.pprint(stuff) - [['spam', 'eggs', 'lumberjack', - 'knights', 'ni'], - 'spam', 'eggs', 'lumberjack', 'knights', - 'ni'] - >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', - ... ('parrot', ('fresh fruit',)))))))) - >>> pp = pprint.PrettyPrinter(depth=6) - >>> pp.pprint(tup) - ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) + >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', + ... ('parrot', ('fresh fruit',)))))))) + >>> pp = pprint.PrettyPrinter(depth=6) + >>> pp.pprint(tup) + ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) .. versionchanged:: 3.4 From a79de4a2a6ff0ca260d1e35c62ebb816d4a4bf78 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Thu, 2 May 2024 12:38:37 +0200 Subject: [PATCH 5/8] fix code indentation for autotests --- Doc/library/pprint.rst | 68 ++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index 209874d9c6a0d1..b7369ddd8b7690 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -86,18 +86,16 @@ Functions integers will be formatted with the ``_`` character for a thousands separator, otherwise underscores are not displayed (the default). - Usage example: - - >>> import pprint - >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> stuff.insert(0, stuff) - >>> pprint.pp(stuff) - [, - 'spam', - 'eggs', - 'lumberjack', - 'knights', - 'ni'] + >>> import pprint + >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] + >>> stuff.insert(0, stuff) + >>> pprint.pp(stuff) + [, + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] .. versionadded:: 3.8 @@ -200,30 +198,28 @@ PrettyPrinter Objects integers will be formatted with the ``_`` character for a thousands separator, otherwise underscores are not displayed (the default). - Usage example: - - >>> import pprint - >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] - >>> stuff.insert(0, stuff[:]) - >>> pp = pprint.PrettyPrinter(indent=4) - >>> pp.pprint(stuff) - [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], - 'spam', - 'eggs', - 'lumberjack', - 'knights', - 'ni'] - >>> pp = pprint.PrettyPrinter(width=41, compact=True) - >>> pp.pprint(stuff) - [['spam', 'eggs', 'lumberjack', - 'knights', 'ni'], - 'spam', 'eggs', 'lumberjack', 'knights', - 'ni'] - >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', - ... ('parrot', ('fresh fruit',)))))))) - >>> pp = pprint.PrettyPrinter(depth=6) - >>> pp.pprint(tup) - ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) + >>> import pprint + >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] + >>> stuff.insert(0, stuff[:]) + >>> pp = pprint.PrettyPrinter(indent=4) + >>> pp.pprint(stuff) + [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] + >>> pp = pprint.PrettyPrinter(width=41, compact=True) + >>> pp.pprint(stuff) + [['spam', 'eggs', 'lumberjack', + 'knights', 'ni'], + 'spam', 'eggs', 'lumberjack', 'knights', + 'ni'] + >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', + ... ('parrot', ('fresh fruit',)))))))) + >>> pp = pprint.PrettyPrinter(depth=6) + >>> pp.pprint(tup) + ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) .. versionchanged:: 3.4 From 5461f945779f73f8656c958f9acb4f906e759313 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Thu, 2 May 2024 13:12:43 +0200 Subject: [PATCH 6/8] Fix identation for autotests --- Doc/library/pprint.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index b7369ddd8b7690..c4ef00782c1dbe 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -91,11 +91,11 @@ Functions >>> stuff.insert(0, stuff) >>> pprint.pp(stuff) [, - 'spam', - 'eggs', - 'lumberjack', - 'knights', - 'ni'] + 'spam', + 'eggs', + 'lumberjack', + 'knights', + 'ni'] .. versionadded:: 3.8 From aeb9488674dba0281fabfed5718958620aad1ab6 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Wed, 26 Jun 2024 13:14:28 +0200 Subject: [PATCH 7/8] Remove duplication of the parameters' description --- Doc/library/pprint.rst | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index c4ef00782c1dbe..97c881ae0af9ef 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -160,43 +160,8 @@ PrettyPrinter Objects Construct a :class:`PrettyPrinter` instance. - :param int indent: - The amount of indentation added for each nesting level. - - :param int width: - The desired maximum number of characters per line in the output. - If a structure cannot be formatted within the width constraint, - a best effort will be made. - - :param depth: - The number of nesting levels which may be printed. - If the data structure being printed is too deep, - the next contained level is replaced by ``...``. - If ``None`` (the default), there is no constraint - on the depth of the objects being formatted. - :type depth: int | None - - :param stream: - A file-like object to which the output will be written - by calling its :meth:`!write` method. - If ``None`` (the default), :data:`sys.stdout` is used. - :type stream: :term:`file-like object` | None - - :param bool compact: - Control the way long :term:`sequences ` are formatted. - If ``False`` (the default), - each item of a sequence will be formatted on a separate line, - otherwise as many items as will fit within the *width* - will be formatted on each output line. - - :param bool sort_dicts: - If ``True`` (the default), dictionaries will be formatted with - their keys sorted, otherwise they will be displayed in insertion order. - - :param bool underscore_numbers: - If ``True``, - integers will be formatted with the ``_`` character for a thousands separator, - otherwise underscores are not displayed (the default). + Arguments have the same meaning as for :func:`~pprint.pp`. + Note that they are in a different order, and that *sort_dicts* defaults to ``True``. >>> import pprint >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] From 4283ad1c019c5b41f9d3f100a029b37eeb0c01f5 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Wed, 26 Jun 2024 13:18:05 +0200 Subject: [PATCH 8/8] Rearrange parameters description in a correct order --- Doc/library/pprint.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst index 97c881ae0af9ef..038543a80b87e4 100644 --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -47,6 +47,12 @@ Functions :param object: The object to be printed. + :param stream: + A file-like object to which the output will be written + by calling its :meth:`!write` method. + If ``None`` (the default), :data:`sys.stdout` is used. + :type stream: :term:`file-like object` | None + :param int indent: The amount of indentation added for each nesting level. @@ -63,12 +69,6 @@ Functions on the depth of the objects being formatted. :type depth: int | None - :param stream: - A file-like object to which the output will be written - by calling its :meth:`!write` method. - If ``None`` (the default), :data:`sys.stdout` is used. - :type stream: :term:`file-like object` | None - :param bool compact: Control the way long :term:`sequences ` are formatted. If ``False`` (the default),