Repository navigation
Conversation
From the Change History section:
- `__pprint__()` describes an object's structure, and the printer makes
all layout decisions.
- Section markers `pprint.VALUES`, `pprint.KWARGS` and `pprint.ITEMS`
say how tuples are read, replacing the reading of tuples by their
shape and the "false-y" name for positional tuple values.
- Add `pprint.Layout` for an object's chrome, the `pprint.DELEGATE`
marker, and the `pprint.Keyword` and `pprint.Entry` types. The
markers are PEP 661 sentinels.
- Specify that the default printer reads the stream permissively, and
that other printers may define their own vocabulary.
- Add `pprint.decompose()`, and the `pprint.LEAF` sentinel that it
returns for a leaf.
- Add `pprint.DescriptionType` for annotating `__pprint__()` methods.
- Add a `hints` attribute to `pprint.Layout`, for particular printers.
- Add a new default printer, `pprint.Printer`, and leave
`pprint.PrettyPrinter` unchanged.
- A printer returns an iterable of lines, and `!p` joins them with
`'\n'`.
- Specify how the default printer lays out, sorts and limits the depth
of nested objects, including keys that wrap.
- The default printer's `expand` option takes a `pprint.Expand` member:
`NEVER`, `FIT` or `ALWAYS`. Its defaults are `width=78`, `indent=4`
and `expand=Expand.FIT`.
- The built-in and standard library container types implement
`__pprint__()`. `str`, `bytes`, `bytearray` and `int` remain leaves
that the printer handles natively.
- Specify when an inherited `__pprint__()` is used, and explain why.
- `dataclasses` and `namedtuple()` generate `__pprint__()` methods.
- The `!p` format spec is a single replacement field,
`f'{obj!p:{printer}}'`, whose value is called without first being
converted to a string.
- The `!p` conversion is a `SyntaxError` in t-strings, and support is
deferred.
- Describe compatibility with Rich, IPython and other pretty printing
protocols.
- Move the Rationale section after the Specification, as PEP 12 now
recommends.
Documentation build overview
11 files changed ·
|
Changes are based on conversations with clankers, Erics, and Larrys.
warsaw
marked this pull request as ready for review
October 23, 2026 19:58
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
From the Change History section:
__pprint__()describes an object's structure, and the printer makes all layout decisions.pprint.VALUES,pprint.KWARGSandpprint.ITEMSsay how tuples are read, replacing the reading of tuples by their shape and the "false-y" name for positional tuple values.pprint.Layoutfor an object's chrome, thepprint.DELEGATEmarker, and thepprint.Keywordandpprint.Entrytypes. The markers are PEP 661 sentinels.pprint.decompose(), and thepprint.LEAFsentinel that it returns for a leaf.pprint.DescriptionTypefor annotating__pprint__()methods.hintsattribute topprint.Layout, for particular printers.pprint.Printer, and leavepprint.PrettyPrinterunchanged.!pjoins them with'\n'.expandoption takes apprint.Expandmember:NEVER,FITorALWAYS. Its defaults arewidth=78,indent=4andexpand=Expand.FIT.__pprint__().str,bytes,bytearrayandintremain leaves that the printer handles natively.__pprint__()is used, and explain why.dataclassesandnamedtuple()generate__pprint__()methods.!pformat spec is a single replacement field,f'{obj!p:{printer}}', whose value is called without first being converted to a string.!pconversion is aSyntaxErrorin t-strings, and support is deferred.