Skip to content

PEP 813: document the pretty print protocol - #8

Open
warsaw wants to merge 2 commits into
ericvsmith:PEP-813-pprintfrom
warsaw:pep813-docs
Open

warsaw wants to merge 2 commits into
ericvsmith:PEP-813-pprintfrom
warsaw:pep813-docs

Conversation

@warsaw

@warsaw warsaw commented Oct 24, 2026 •

Copy link
Copy Markdown

A first draft of the documentation for PEP 813 (pythongh-145153). Before this, the branch documented PyObject_Pretty(), Interpolation.printer and convert(..., printer), but nothing in pprint itself.

Doc/library/pprint.rst

  • A new "The pretty print protocol" section: an overview with a worked Bass example, then Printer and Expand, the description stream (VALUES, KWARGS, ITEMS, DELEGATE, Layout, Keyword, Entry, BreakableString/BreakableBytes, FormattableNumber, DescriptionType), and decompose() with LEAF.
  • A pointer to the protocol in the module introduction.
  • PrettyPrinter is marked soft-deprecated, as the PEP now proposes.

Elsewhere

  • Doc/reference/datamodel.rst: a new object.__pprint__() entry, including the MRO rule.
  • Doc/builtins/stdtypes.rst: !p is in the list of conversions, and its paragraph now covers the printer spec, None, the SyntaxError for other specs and the TypeError cases, with an example.
  • Doc/library/string.rst and Doc/reference/lexical_analysis.rst: both grammars now allow p. The format string prose describes !p, and that a spec after it pads the result.
  • Doc/library/dataclasses.rst and Doc/library/collections.rst: the generated __pprint__(), and that a hand-written __repr__() turns it off.
  • Doc/whatsnew/3.16.rst: a PEP 813 section and highlight, the soft deprecation and PyObject_Pretty() under C API.

Checks. sphinx-lint is clean, and a full nitpicky HTML build with CPython's pinned requirements shows no warnings in the changed files. Every example's output was checked against the built interpreter. The !p examples use :force:, since Pygments doesn't know the conversion.

NEWS. Library, Core and Builtins, and C API entries for pythongh-145153, and the What's New entries reference it too.

🤖 Generated with Claude Code

Add a reference for the protocol to the pprint docs: Printer and Expand,
the description stream vocabulary (the section markers, DELEGATE, Layout,
Keyword, Entry, the marker classes and DescriptionType), decompose() and
LEAF.  Mark PrettyPrinter soft deprecated.

Add object.__pprint__() to the data model reference.  Describe !p in the
f-string and format string docs, and add it to both grammars.  Note the
generated __pprint__() for dataclasses and named tuples.  Add What's New
entries for the protocol, the soft deprecation and PyObject_Pretty().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@warsaw
warsaw requested a review from ericvsmith as a code owner October 24, 2026 00:30
Add Library, Core and Builtins, and C API NEWS entries for the pretty
print protocol, and reference pythongh-145153 in the What's New entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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