-
-
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
Open
warsaw
wants to merge
19
commits into
python:main
Choose a base branch
from
warsaw:pep-813-pprint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
398f467
PEP 813: The Pretty Print Protocol
warsaw 25c70f7
The Elder Statesmen of Python
warsaw 5555617
Fix markup errors
warsaw cd0a257
One more linting bug
warsaw 1d4b9d1
Exmaple fixes
warsaw b8fc7e4
Alone again, naturally
warsaw 263a95b
Update peps/pep-0813.rst
warsaw 143cb6c
The dunder is __pprint__(), not __pretty__()
warsaw a8598f7
Update peps/pep-0813.rst
warsaw 1a96c8d
Merge branch 'pep-813-pprint' of github.com:warsaw/peps into pep-813-…
warsaw 2703f5c
Update based on @AA-Turner's feedback
warsaw 686fc4d
Update peps/pep-0813.rst
warsaw 94d20f5
Merge branch 'main' into pep-813-pprint
warsaw 1cf369c
Merge branch 'main' into pep-813-pprint
warsaw 062eef6
Update CODEOWNERS
warsaw 8f744fb
Merge branch 'main' into pep-813-pprint
warsaw c8212a9
Merge branch 'main' into pep-813-pprint
warsaw 93b0d6e
Merge branch 'main' into pep-813-pprint
warsaw dfd5667
Update the PEP to match the latest decisions, and reference implement…
warsaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix markup errors
- Loading branch information
commit 55556175c45d04fc8b36784159e61278c55f6315
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| PEP: 813 | ||||||
| Title: The Pretty Print Protocol | ||||||
| Author: Barry Warsaw <[email protected]>, | ||||||
| Eric V. Smith <eric at trueblade.com> | ||||||
| Eric V. Smith <eric@trueblade.com> | ||||||
| Discussions-To: Pending | ||||||
| Status: Draft | ||||||
| Type: Standards Track | ||||||
|
|
@@ -36,7 +36,7 @@ Pretty printing is very useful for displaying complex data structures, like dict | |||||
| 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. | ||||||
|
|
||||||
| By extending the built-in :py:func:`print` function to automatically pretty print its output, this feature is | ||||||
| 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. | ||||||
|
|
||||||
|
|
@@ -57,10 +57,10 @@ representation of their instances. This augments ``__repr__()`` which, prior to | |||||
| 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. | ||||||
warsaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ``__pretty__()`` is optional; if missing, the standard pretty printers fall back to ``__repr__()`` for full | ||||||
| backward compatibility (technically speaking, :meth:`pprint.saferepr` is used). However, if defined on a | ||||||
| class, ``__pretty__()`` has the same argument signature as :py:func:`PrettyPrinter.format`, taking four | ||||||
| arguments: | ||||||
| ``__pretty__()`` is optional; if missing, the standard pretty printers fall back to ``__repr__()`` | ||||||
| for full backward compatibility (technically speaking, :py:func:`python:pprint.saferepr` is used). | ||||||
|
||||||
| However, if defined on a class, ``__pretty__()`` has the same argument signature as | ||||||
| :py:meth:`python:pprint.PrettyPrinter.format`, taking four arguments: | ||||||
warsaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| * ``object`` - the object to print, which is effectively always ``self`` | ||||||
| * ``context`` - a dictionary mapping the ``id()`` of objects which are part of the current presentation | ||||||
|
|
@@ -70,23 +70,24 @@ arguments: | |||||
|
|
||||||
| Similarly, ``__pretty__()`` returns three values, the string to be used as the pretty printed representation, | ||||||
warsaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| a boolean indicating whether the returned value is "readable", and a boolean indicating whether recursion has | ||||||
| been detected. In this context, "readable" means the same as :meth:`PrettyPrinter.isreadable`, i.e. that the | ||||||
| returned value can be used to reconstruct the original object using ``eval()``. | ||||||
| been detected. In this context, "readable" means the same as | ||||||
| :py:meth:`python:pprint.PrettyPrinter.isreadable`, i.e. that the returned value can be used to reconstruct the | ||||||
|
||||||
| :py:meth:`python:pprint.PrettyPrinter.isreadable`, i.e. that the returned value can be used to reconstruct the | |
| :py:meth:`~pprint.PrettyPrinter.isreadable`, i.e. that the returned value can be used to reconstruct the |
warsaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
warsaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.