-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
PEP 813: The Pretty Print Protocol #4690
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
base: main
Are you sure you want to change the base?
Conversation
hugovk
left a comment
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.
Looks useful!
Co-authored-by: Hugo van Kemenade <[email protected]>
AA-Turner
left a comment
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.
Sorry for the slight delay in initial review!
Mostly editorial comments in line, a couple of questions where I didn't follow the text too.
A slightly more substantive point I think it'd be useful to address is what style/form of prettiness will be chosen -- I'm thinking here of the proposed(?) change to pprint to add block-style formatting, similar to how code is often formatted in source form, rather than the more traditional pprint approach (as illustrated in the examples here). Personally, I'd always want to use the block-style if possible, but my understanding of the current proposal is that options like that wouldn't be possible.
A
willingc
left a comment
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.
Nice. A few clarifications in addition to Adam's.
| includes a class and APIs which users can invoke to format and print more readable representations of objects. | ||
| Important use cases include pretty printing large dictionaries and other complicated objects. | ||
|
|
||
| The ``pprint`` module is great as far as it goes. This PEP builds on the features of this module to provide |
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 ``pprint`` module is great as far as it goes. This PEP builds on the features of this module to provide | |
| The ``pprint`` module provides fundamentals for user-readable information display. This PEP builds on the features of this module to provide |
| Important use cases include pretty printing large dictionaries and other complicated objects. | ||
|
|
||
| The ``pprint`` module is great as far as it goes. This PEP builds on the features of this module to provide | ||
| more customization and convenience. |
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.
| more customization and convenience. | |
| more customization, display structure, and user convenience. |
| Pretty printing is very useful for displaying complex data structures, like dictionaries read from JSON | ||
| content. By providing a way for classes to customize how their instances participate in pretty printing, | ||
| users have more options for visually improving the display and debugging of their complex data. |
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.
| Pretty printing is very useful for displaying complex data structures, like dictionaries read from JSON | |
| content. By providing a way for classes to customize how their instances participate in pretty printing, | |
| users have more options for visually improving the display and debugging of their complex data. | |
| Pretty printing is very useful for displaying complex data structures, like dictionaries read from JSON | |
| content. Through class customization options for pretty printing, | |
| users have more options for visually improving the display and debugging of their complex data. |
| By extending the built-in :func:`print` function to automatically pretty print its output, this feature is | ||
| made even more convenient, since no extra imports are required, and users can easily just piggyback on | ||
| well-worn "print debugging" patterns, at least for the most common use cases. |
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.
| By extending the built-in :func:`print` function to automatically pretty print its output, this feature is | |
| made even more convenient, since no extra imports are required, and users can easily just piggyback on | |
| well-worn "print debugging" patterns, at least for the most common use cases. | |
| By extending the built-in :func:`print` function to automatically pretty print its output, user-readable display is | |
| made even more convenient. Since no extra imports are required, users can easily piggyback on | |
| well-worn "print debugging" patterns for most common use cases. |
| made even more convenient, since no extra imports are required, and users can easily just piggyback on | ||
| well-worn "print debugging" patterns, at least for the most common use cases. | ||
|
|
||
| These two extensions work independently, but hand-in-hand can provide a powerful and convenient new feature. |
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.
| These two extensions work independently, but hand-in-hand can provide a powerful and convenient new feature. | |
| These two extensions, class customization for pretty printing and default print behavior, work independently but can be used in conjunction to provide a powerful and convenient user display of information. |
peps/pep-0813.rst
Outdated
| Classes can implement a new dunder method, ``__pretty__()`` which if present, generates the pretty printed | ||
| representation of their instances. This augments ``__repr__()`` which, prior to this proposal, was the only | ||
| method used to generate a pretty representation of the object. Since object reprs provide functionality | ||
| distinct from pretty printing, some classes may want more control over their pretty display. |
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.
| distinct from pretty printing, some classes may want more control over their pretty display. | |
| structured representation distinct from pretty printing, some classes may benefit from more control over pretty visual display of their instances. |
No worries! I was on vacation so I'm just getting back to this now.
Very much appreciated!
While I prefer to defer substantive discussions to the inevitable mega-DPO thread, I think a possible way to handle this would be to use a different I'll have to discuss with @ericvsmith as we move forward with the proposal. |
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: Carol Willing <[email protected]>
Basic requirements (all PEP Types)
pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) andPEPheaderAuthororSponsor, and formally confirmed their approvalAuthor,Status(Draft),TypeandCreatedheaders filled out correctlyPEP-Delegate,Topic,RequiresandReplacesheaders completed if appropriate.github/CODEOWNERSfor the PEPStandards Track requirements
Python-Versionset to valid (pre-beta) future Python version, if relevantDiscussions-ToandPost-History📚 Documentation preview 📚: https://pep-previews--4690.org.readthedocs.build/pep-0813/