Skip to content

PEP 813: Major update based on 2026 sprint collaboration - #5191

Open
warsaw wants to merge 6 commits into
python:mainfrom
warsaw:pprint-next
Open

warsaw wants to merge 6 commits into
python:mainfrom
warsaw:pprint-next

Conversation

@warsaw

@warsaw warsaw commented Oct 22, 2026

Copy link
Copy Markdown
Member

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.

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.
@warsaw
warsaw requested a review from ericvsmith as a code owner October 22, 2026 22:05
@warsaw warsaw self-assigned this Oct 22, 2026
@warsaw
warsaw marked this pull request as draft October 22, 2026 22:05
@hugovk hugovk changed the title Major update of the PEP based on 2026 sprint collaboration PEP 813: Major update based on 2026 sprint collaboration Oct 22, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Changes are based on conversations with clankers, Erics, and Larrys.
@warsaw
warsaw marked this pull request as ready for review October 23, 2026 19:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant