Skip to content

Improve documentation for pprint module #115986

Description

@AlexWaygood

Documentation

The documentation for the pprint module could be improved in many respects:

  • Most users will probably only ever need to use pprint.pp() or pprint.pprint(), but these are buried halfway down the module. It would be nice if these were the first things on the page.
  • All examples in the documentation use pprint.pprint(), which has some unexpected behaviour. For example, it sorts dictionaries by default, which is somewhat unintuitive now that dictionaries maintain insertion order. I suggest we change the examples to use pprint.pp() instead, which has the more intuitive default of sort_dicts=False.
  • Similarly, the docs for pprint.pprint() could explicitly call out that it has unintuitive defaults for things such as sort_dicts and link to pprint.pp()
  • Some links in the module's documentation incorrectly point to the module itself (pprint) instead of the function pprint.pprint().

These don't all necessarily need to be tackled in the same PR

Linked PRs

Activity

  1. Privat33r-dev commented on Feb 27, 2024

    @Privat33r-dev
    Contributor

    Can I be assigned? I can do most of it in a day or two.

  2. gaogaotiantian commented on Feb 27, 2024

    @gaogaotiantian
    Member

    The fact pp is not an alias for pprint surprised me. Personally I'd prefer to use a function that better explains itself (pprint is easier to understand than pp), without knowing the difference between them. I have some doubts about using pp as the default in all the examples, but that's just my two cents.

  3. added a commit that references this issue on Feb 28, 2024
  4. Privat33r-dev commented on Feb 28, 2024

    @Privat33r-dev
    Contributor

    Progress tracker

    • Most users will probably only ever need to use pprint.pp() or pprint.pprint(), but these are buried halfway down the module. It would be nice if these were the first things on the page.
    • All examples in the documentation use pprint.pprint(), which has some unexpected behaviour. For example, it sorts dictionaries by default, which is somewhat unintuitive now that dictionaries maintain insertion order. I suggest we change the examples to use pprint.pp() instead, which has the more intuitive default of sort_dicts=False.
    • Similarly, the docs for pprint.pprint() could explicitly call out that it has unintuitive defaults for things such as sort_dicts and link to pprint.pp()
    • Some links in the module's documentation incorrectly point to the module itself (pprint) instead of the function pprint.pprint().
  5. added 5 commits that reference this issue on Feb 28, 2024
  6. Privat33r-dev commented on Feb 28, 2024

    @Privat33r-dev
    Contributor

    Since pp as a default example might be considered controversial, I will put in the second PR. To avoid merging issues, I will push second PR after the first one is accepted.

  7. erlend-aasland commented on Feb 28, 2024

    @erlend-aasland
    Contributor

    The pprint docs could make good use of param list markup.

    UPDATE: PR => #116085

  8. added a commit that references this issue on Feb 28, 2024
  9. added a commit that references this issue on Feb 28, 2024
  10. 29 remaining items

  11. added a commit that references this issue on Apr 22, 2024
  12. Privat33r-dev commented on Apr 26, 2024

    @Privat33r-dev
    Contributor

    @erlend-aasland let's duplicate the params list in 1 function and in the class. DRY would be violated, but readability would be improved, which is more important than blindly following the principle.

  13. erlend-aasland commented on Apr 29, 2024

    @erlend-aasland
    Contributor

    @erlend-aasland let's duplicate the params list in 1 function and in the class. DRY would be violated, but readability would be improved, which is more important than blindly following the principle.

    Can you propose a PR?

  14. added a commit that references this issue on Jun 27, 2024
  15. Privat33r-dev commented on Jun 27, 2024

    @Privat33r-dev
    Contributor

    I guess it's resolved? :)

  16. encukou commented on Jun 27, 2024

    @encukou
    Member

    let's duplicate the params list in 1 function and in the class. DRY would be violated, but readability would be improved, which is more important than blindly following the principle.

    Ah, I missed this comment before pointing it in the review, so, for posterity:

    IMO, including the full list only once, and linking to it from the other locations, is better -- especially with one function we prefer (pp), while others are backward-compatible defaults (pprint), and more special use (pformat & PrettyPrinter).
    Also, this way lends itself to listing the differences in argument order and defaults, which makes them much easier to spot.

    Thanks for implementing that! The PR was just merged.

    I guess it's resolved? :)

    I think so! @erlend-aasland, is there anything else you want to improve?

  17. added 2 commits that reference this issue on Jun 27, 2024
  18. erlend-aasland commented on Jun 27, 2024

    @erlend-aasland
    Contributor

    @erlend-aasland, is there anything else you want to improve?

    No, I think we're good for now :)

  19. added 2 commits that reference this issue on Jun 28, 2024
  20. added a commit that references this issue on Jun 30, 2024
  21. added a commit that references this issue on Jul 11, 2024
  22. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions