Skip to content

Conversation

@warsaw
Copy link
Member

@warsaw warsaw commented Nov 7, 2025

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation
    • Rationale
    • Specification
    • Backwards Compatibility
    • Security Implications
    • How to Teach This
    • Reference Implementation
    • Rejected Ideas
    • Open Issues
  • Python-Version set to valid (pre-beta) future Python version, if relevant
  • Any project stated in the PEP as supporting/endorsing/benefiting from the PEP formally confirmed such
  • Right before or after initial merging, PEP discussion thread created and linked to in Discussions-To and Post-History

📚 Documentation preview 📚: https://pep-previews--4690.org.readthedocs.build/pep-0813/

@warsaw warsaw requested a review from a team as a code owner November 7, 2025 17:21
warsaw added a commit to warsaw/cpython that referenced this pull request Nov 7, 2025
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful!

@hugovk hugovk added the new-pep A new draft PEP submitted for initial review label Nov 7, 2025
Co-authored-by: Hugo van Kemenade <[email protected]>
@warsaw warsaw self-assigned this Nov 7, 2025
Copy link
Member

@AA-Turner AA-Turner left a 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

Comment on lines +15 to +16
This PEP describes the "pretty print protocol", a collection of changes proposed to make pretty printing more
customizable and convenient.
Copy link
Member

@AA-Turner AA-Turner Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be useful to note that implementation is via the __pretty__ dunder (& the change to print?) here, even if just in a single sentence.

==========

"Pretty printing" is a feature which provides a capability to format object representations for better
readability. The core functionality is implemented by the standard library :mod:`pprint`. ``pprint``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
readability. The core functionality is implemented by the standard library :mod:`pprint`. ``pprint``
readability. The core functionality is implemented by the standard library :mod:`pprint` module. ``pprint``


"Pretty printing" is a feature which provides a capability to format object representations for better
readability. The core functionality is implemented by the standard library :mod:`pprint`. ``pprint``
includes a class and APIs which users can invoke to format and print more readable representations of objects.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implicitly versus repr(), perhaps useful to say so explicitly?

"Pretty printing" is a feature which provides a capability to format object representations for better
readability. The core functionality is implemented by the standard library :mod:`pprint`. ``pprint``
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say a key use case is interactive debugging, pretty-printing by default is a big reason I use IPython.

Specification
=============

There are two parts to this proposal.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There are two parts to this proposal.
There are two parts to this proposal;
a new dunder method and a change to :func:`print`.

* ``maxlevels`` - the requested limit to recursion
* ``levels`` - the current recursion level

Similarly, ``__pretty__()`` returns three values, the string to be used as the pretty printed representation,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Similarly, ``__pretty__()`` returns three values, the string to be used as the pretty printed representation,
Similarly, ``__pretty__()`` returns three values: the string to be used as the pretty printed representation,

Examples
========

A custom ``__pprint__()`` method can be used to customize the representation of the object:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A custom ``__pprint__()`` method can be used to customize the representation of the object:
A custom ``__pretty__()`` method can be used to customize the representation of the object:

``__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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this four in addition to self? (i.e. def __pretty__(self, object, context, maxlevels, levels): ...)

>>> class Custom:
... def __str__(self): return 'my str'
... def __repr__(self): return 'my repr'
... def __pprint__(self, context, maxlevels, level):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
... def __pprint__(self, context, maxlevels, level):
... def __pretty__(self, context, maxlevels, level):

Comment on lines +108 to +109
>>> pprint.pp(Custom())
my pprint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intent for PrettyPrinter to change to respect __pretty__ methods? I don't think I saw that above in the spec, but I may have missed it, sorry!

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

Labels

new-pep A new draft PEP submitted for initial review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants