[Python-ideas] __repr__: to support pprint

Serhiy Storchaka storchaka at gmail.com
Wed Mar 1 14:49:39 EST 2017


On 01.03.17 16:35, Paul Moore wrote:
> On 1 March 2017 at 13:50, Steven D'Aprano <steve at pearwood.info> wrote:
>> It is possible that we could come up with a pretty-printing protocol,
>> but that wouldn't be a trivial job.
>
> I'd be inclined to do this via simplegeneric. Let pprint do what it
> currently does, but allow users to register implementations for
> specific classes as they wish.

That is how pprint is implemented now. It register implementations for 
specific classes and dispatch them by type (or rather by __repr__ 
implementation). But these functions have too complex and non-extensible 
signatures and that is why this is an implementation detail.

There is an open issue for a pretty-printing protocol, but it is far 
from any progress.



More information about the Python-ideas mailing list