@@ -54,24 +54,26 @@ There are two parts to this proposal.
5454
5555Classes can implement a new dunder method, ``__pretty__() `` which if present, generates the pretty printed
5656representation of their instances. This augments ``__repr__() `` which, prior to this proposal, was the only
57- method used to generate a pretty representation of the object. Since the built-in :py:func: `repr ` function
58- provides functionality potentially separate from pretty printing, some classes may want more control over
59- object display between those two use cases.
57+ method used to generate a pretty representation of the object. Since object reprs provide functionality
58+ distinct from pretty printing, some classes may want more control over their pretty display.
6059
6160``__pretty__() `` is optional; if missing, the standard pretty printers fall back to ``__repr__() `` for full
62- backward compatibility. However, if defined on a class, ``__pretty__() `` has the same argument signature as
63- :py:func: `PrettyPrinter.format `, taking four arguments:
61+ backward compatibility (technically speaking, :meth: `pprint.saferepr ` is used). However, if defined on a
62+ class, ``__pretty__() `` has the same argument signature as :py:func: `PrettyPrinter.format `, taking four
63+ arguments:
6464
6565* ``object `` - the object to print, which is effectively always ``self ``
6666* ``context `` - a dictionary mapping the ``id() `` of objects which are part of the current presentation
6767 context
6868* ``maxlevels `` - the requested limit to recursion
6969* ``levels `` - the current recursion level
7070
71- See :py:func: `PrettyPrinter.format ` for details.
71+ Similarly, ``__pretty__() `` returns three values, the string to be used as the pretty printed representation,
72+ a boolean indicating whether the returned value is "readable", and a boolean indicating whether recursion has
73+ been detected. In this context, "readable" means the same as :meth: `PrettyPrinter.isreadable `, i.e. that the
74+ returned value can be used to reconstruct the original object using ``eval() ``.
7275
73- Unlike that function, ``__pretty__() `` returns a single value, the string to be used as the pretty printed
74- representation.
76+ See :py:func: `PrettyPrinter.format ` for details.
7577
7678
7779A new argument to built-in ``print ``
@@ -172,13 +174,7 @@ None at this time.
172174Open Issues
173175===========
174176
175- As currently defined, the ``__pretty__() `` method is defined as taking four arguments and returning
176- a single string. This is close to -- but not quite -- the full signature for
177- ``PrettyPrinter.format() ``, and was chosen for reference implementation convenience. It's not
178- clear that custom pretty representations need ``context ``, ``maxlevels ``, and ``levels ``, so perhaps
179- the argument list should be simplified? If not, then perhaps ``__pretty__() `` should *exactly *
180- match ``PrettyPrinter.format() ``? That does, however complicate the protocol for users.
181-
177+ TBD
182178
183179Acknowledgements
184180================
0 commit comments