GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-115986 Improve pprint docs formatting by Privat33r-dev · Pull Request #117401 · python/cpython

Conversation

@Privat33r-dev

@Privat33r-dev Privat33r-dev commented Mar 31, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The change improves readability.
Suggested in the #116085 PR discussion.

  • Issue: Improve documentation for pprint module #115986

📚 Documentation preview 📚: https://cpython-previews--117401.org.readthedocs.build/en/117401/library/pprint.html

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting review docs Documentation in the Doc dir skip news labels Mar 31, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Mar 31, 2024
Improve documentation for pprint module #115986
Closed
@Privat33r-dev
Move pprinter parameters description to the table
cc92c08
The change improves readability.
Suggested in the GH#116085 PR discussion.
@Privat33r-dev
Privat33r-dev force-pushed the add-params-table-115986 branch from 33e0842 to cc92c08 Compare March 31, 2024 12:16
@erlend-aasland

erlend-aasland commented Mar 31, 2024

Copy link
Copy Markdown
Contributor

If we're putting the params list in the pprint.pprint function docs, we could just as well use the standardised Sphinx param list markup (:param:, :type:, etc.). We'll probably refer to pprint.pprint from the pprint.pp and the PrettyPrinter docs anyway, so using the standard markup seems like a better way to me. cc. @AlexWaygood @hugovk

Privat33r-dev reacted with thumbs up emoji Privat33r-dev reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
AlexWaygood self-requested a review March 31, 2024 22:31
@Privat33r-dev

Privat33r-dev commented Apr 1, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@erlend-aasland, I do completely agree that :param: will look better, especially considering the fact that we want to keep parameters' types as well and :param: look much more suitable for this purpose. I was hesitant to express my opinion earlier as everyone seemed to agree on table's solution, but now I see that it made more sense to speak my mind.

Moreover, I want to address the whole "pp vs pprint" thing. If we are writing docs from the developer's perspective, it would seem more logical to write the full description in one function's docs and just mention in another that it's an alias to keep everything DRY and readable (please, ignore formatting and minor details):

pprint.pp(object, stream=None, indent=1, width=80, depth=None, *, compact=False, sort_dicts=False, 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 in the interactive interpreter instead of the [print()] function for inspecting values (you can even reassign print = pprint.pp for use within a scope).

The configuration parameters stream, indent, width, depth, compact, sort_dicts and underscore_numbers are passed to the [PrettyPrinter] constructor and their meanings are as described in its documentation below.

** PrettyPrinter PARAMS HERE **

pprint.pprint(object, stream=None, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True, underscore_numbers=False)
Alias to pprint.pp. Note that sort_dicts is True by default and you might want to use [pp()] instead where it is False by default.

It feels like it would make the most sense, because here we would give all the usage info on pprint.pp and only then mention "pprint.pprint" and other stuff.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Apr 29, 2024

Copy link
Copy Markdown
Contributor

@Privat33r-dev, do you have a draft PR of your suggestion?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev

Privat33r-dev commented Apr 29, 2024

Copy link
Copy Markdown
Contributor Author

@Privat33r-dev, do you have a draft PR of your suggestion?

not yet, but I can make (or rather edit existing) one if my proposed change sounds good

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Apr 30, 2024

Copy link
Copy Markdown
Contributor

not yet, but I can make (or rather edit existing) one if my proposed change sounds good

I think a draft PR would be interesting, but only if you have time available for it; I find it easier to decide on doc layouts when they are rendered :)

Privat33r-dev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev
Make pprint doc with params markup
5797858
@Privat33r-dev Privat33r-dev changed the title gh-115986 Move pprinter parameters description to the table gh-115986 Improve pprint docs formatting Apr 30, 2024
@Privat33r-dev

Privat33r-dev commented Apr 30, 2024

Copy link
Copy Markdown
Contributor Author

not yet, but I can make (or rather edit existing) one if my proposed change sounds good

I think a draft PR would be interesting, but only if you have time available for it; I find it easier to decide on doc layouts when they are rendered :)

done, you can check it out :)

erlend-aasland reacted with hooray emoji erlend-aasland reacted with heart emoji
All reactions
  • 🎉 1 reaction
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented May 2, 2024

Copy link
Copy Markdown
Contributor

Thanks! I like this very much. We could use Sphinx placeholders to minimise the duplication. I'm not sure if it is worth it, though, because you'd have to create one placeholder for each parameter description.

Privat33r-dev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev
Fix formatting
e614722
Indentation of code blocks made them nested
"Version changed" is better placed after the code block
@Privat33r-dev

Privat33r-dev commented May 2, 2024

Copy link
Copy Markdown
Contributor Author

There are 2 differences between the params table:

  1. "object" presence as the first param
  2. (the default) placement for sort_dicts param

Even if we technically can make a placeholder for table (by "table" I mean params list), the first difference is resolved by putting :param: before the table, but the second difference could be resolved only by moving the table to pprint.pprint or by somehow replacing the content of the placeholder (which is kind of hacky).

We can keep it DAMP for now since there is low change of significant changes in the pprint.pprint and in case if there are some changes (which will unlikely involve parameters), we can add comment to rst that edit should be made twice.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev

Privat33r-dev commented May 2, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

My recent change
Move code out of parameter

Screenshots

Before

After

Move code out of "changed in version" and move the latter down
Screenshots

Before

After

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented May 2, 2024

Copy link
Copy Markdown
Contributor

Moving the example code out of the parameter list sounds good. IMO we should never embed code examples in parameter lists, since it is (IMO) visually cluttering.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev

Privat33r-dev commented May 2, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Moving the example code out of the parameter list sounds good. IMO we should never embed code examples in parameter lists, since it is (IMO) visually cluttering.

Moving example code in the param was unintentional consequence of adding params :)

I am not sure how to fix the tests though. Can you give an advise? This change will likely do the trick:
image

But I'd prefer to keep the indentation and avoid "usage example" and similar things to keep the document's consistency.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented May 2, 2024

Copy link
Copy Markdown
Contributor

I am not sure how to fix the tests though

You need to adjust the indentation so it matches the expected output; AFAIK, there is no other way.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev
Fix formatting for tests
ebcafbf
@Privat33r-dev

Privat33r-dev commented May 2, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I am not sure how to fix the tests though

You need to adjust the indentation so it matches the expected output; AFAIK, there is no other way.

putting additional newline between "usage example" and code fixed the indentation. I tried to use comment (.. example\n\n{code}), but it made example visually disappear (since I guess the code become child of comment). I guess we go with "usage example"s now. But, I guess, it makes the doc more explicit now :)

erlend-aasland reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev
fix code indentation for autotests
a79de4a
@Privat33r-dev

Privat33r-dev commented May 2, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I figured out that the problem wasn't in the indentation of the code block but because my IDE decided to align code inside of the code blocks on <shift>+<tab>.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev

Privat33r-dev commented May 2, 2024

Copy link
Copy Markdown
Contributor Author

image
Well, after watching the Steven He's "Failure Management" course, I can confidently say that the problem is still in indentation and reducing amount of failures from 3 to 1 is a partial success.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev
Fix identation for autotests
5461f94
@Privat33r-dev

Privat33r-dev commented May 2, 2024

Copy link
Copy Markdown
Contributor Author

Failure has been successfully managed. Ready for review :)

P.S. Why does doctest job take 16 minutes? Diving a bit deeper I noticed that doctest.py does not parallelize jobs, it might be the problem.

erlend-aasland reacted with hooray emoji erlend-aasland reacted with eyes emoji
All reactions
  • 🎉 1 reaction
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou
encukou reviewed Jun 18, 2024
View reviewed changes
Comment thread Doc/library/pprint.rst
*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.

@encukou encukou Jun 18, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for PrettyPrinter is still below. Maybe this should be:

The arguments have the same meaning as for :func:`~pprint.pprint`.
Note that *sort_dicts* defaults to ``True``.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Privat33r-dev Privat33r-dev Jun 26, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why "its" was changed to "the", as arguments description is above (in the pp.pprint description).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/library/pprint.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pprint.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Privat33r-dev
Privat33r-dev commented Jun 26, 2024
View reviewed changes
Comment thread Doc/library/pprint.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev
Remove duplication of the parameters' description
aeb9488
Privat33r-dev
Privat33r-dev commented Jun 26, 2024
View reviewed changes
Comment thread Doc/library/pprint.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Privat33r-dev and others added 2 commits June 26, 2024 13:18
@Privat33r-dev
Rearrange parameters description in a correct order
4283ad1
@hugovk
Merge branch 'main' into add-params-table-115986
3918538
@hugovk

hugovk commented Jun 26, 2024

Copy link
Copy Markdown
Member

I've merged main in, should fix the CI failure (check-warnings.py: error: unrecognized arguments: --fail-if-new-news-nit).

Privat33r-dev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev

Privat33r-dev commented Jun 26, 2024

Copy link
Copy Markdown
Contributor Author

I've merged main in, should fix the CI failure (check-warnings.py: error: unrecognized arguments: --fail-if-new-news-nit).

Thanks. It worked :)

hugovk reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou
encukou approved these changes Jun 27, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jun 27, 2024
@encukou
encukou merged commit 0890ad7 into python:main Jun 27, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Jun 27, 2024
@encukou

encukou commented Jun 27, 2024

Copy link
Copy Markdown
Member

Thank you!

Privat33r-dev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou encukou added the needs backport to 3.13 only security fixes label Jun 27, 2024
@miss-islington-app

This comment was marked as outdated.

Sign in to view
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 27, 2024
@Privat33r-dev @hugovk @miss-islington
pythongh-115986 Improve pprint docs formatting (pythonGH-117401)
96807a1
* Move pprinter parameters description to the table

The change improves readability.
Suggested in the GHGH-116085 PR discussion.

* Make pprint doc with params markup

* Fix formatting
Indentation of code blocks made them nested
"Version changed" is better placed after the code block

* Fix formatting for tests

* fix code indentation for autotests

* Fix identation for autotests

* Remove duplication of the parameters' description

* Rearrange parameters description in a correct order

---------

(cherry picked from commit 0890ad7)

Co-authored-by: Kerim Kabirov <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
@bedevere-app

bedevere-app Bot commented Jun 27, 2024

Copy link
Copy Markdown

GH-121098 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 27, 2024
@encukou encukou added the needs backport to 3.12 only security fixes label Jun 27, 2024
@miss-islington-app

This comment was marked as outdated.

Sign in to view
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 27, 2024
@Privat33r-dev @hugovk @miss-islington
pythongh-115986 Improve pprint docs formatting (pythonGH-117401)
c9b62d9
* Move pprinter parameters description to the table

The change improves readability.
Suggested in the GHGH-116085 PR discussion.

* Make pprint doc with params markup

* Fix formatting
Indentation of code blocks made them nested
"Version changed" is better placed after the code block

* Fix formatting for tests

* fix code indentation for autotests

* Fix identation for autotests

* Remove duplication of the parameters' description

* Rearrange parameters description in a correct order

---------

(cherry picked from commit 0890ad7)

Co-authored-by: Kerim Kabirov <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
@bedevere-app

bedevere-app Bot commented Jun 27, 2024

Copy link
Copy Markdown

GH-121099 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Jun 27, 2024
encukou pushed a commit that referenced this pull request Jun 28, 2024
@miss-islington @Privat33r-dev @hugovk
[3.13] gh-115986 Improve pprint docs formatting (GH-117401) (GH-121098)
394dc93
* Move pprinter parameter descriptions to a table

* Make pprint doc with params markup

* Remove duplication of the parameters' description

---------

(cherry picked from commit 0890ad7)

Co-authored-by: Kerim Kabirov <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
encukou added a commit that referenced this pull request Jun 28, 2024
@miss-islington @Privat33r-dev
@hugovk @encukou
[3.12] gh-115986 Improve pprint docs formatting (GH-117401) (GH-121099)
3a420de
gh-115986 Improve pprint docs formatting (GH-117401)

* Move pprinter parameters description to the table

The change improves readability.
Suggested in the GHGH-116085 PR discussion.

* Make pprint doc with params markup

* Fix formatting
Indentation of code blocks made them nested
"Version changed" is better placed after the code block

* Fix formatting for tests

* fix code indentation for autotests

* Fix identation for autotests

* Remove duplication of the parameters' description

* Rearrange parameters description in a correct order

---------

(cherry picked from commit 0890ad7)

Co-authored-by: Kerim Kabirov <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
@Privat33r-dev @hugovk @mrahtz
pythongh-115986 Improve pprint docs formatting (pythonGH-117401)
ba4d054
* Move pprinter parameters description to the table

The change improves readability.
Suggested in the GH#116085 PR discussion.

* Make pprint doc with params markup

* Fix formatting
Indentation of code blocks made them nested
"Version changed" is better placed after the code block

* Fix formatting for tests

* fix code indentation for autotests

* Fix identation for autotests

* Remove duplication of the parameters' description

* Rearrange parameters description in a correct order

---------

Co-authored-by: Hugo van Kemenade <[email protected]>
@erlend-aasland

erlend-aasland commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

Next time, remember to edit the commit message upon merging, @encukou :)

Thanks for the contribution, Kerim!

Privat33r-dev and encukou reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@Privat33r-dev @hugovk @estyxx
pythongh-115986 Improve pprint docs formatting (pythonGH-117401)
f298a44
* Move pprinter parameters description to the table

The change improves readability.
Suggested in the GH#116085 PR discussion.

* Make pprint doc with params markup

* Fix formatting
Indentation of code blocks made them nested
"Version changed" is better placed after the code block

* Fix formatting for tests

* fix code indentation for autotests

* Fix identation for autotests

* Remove duplication of the parameters' description

* Rearrange parameters description in a correct order

---------

Co-authored-by: Hugo van Kemenade <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou approved these changes
@AlexWaygood AlexWaygood Awaiting requested review from AlexWaygood

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Privat33r-dev @erlend-aasland @hugovk @encukou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.