Improving pretty-printing in Python
Improving pretty-printing in Python
Posted Mar 19, 2020 1:19 UTC (Thu) by NYKevin (subscriber, #129325)Parent article: Improving pretty-printing in Python
If you want to do this "at the level of application I/O," I would tend to assume you'd just subclass reprlib.Repr and implement the repr_foo() method overrides. Since that's already in the standard library, I'm not sure I understand what they are proposing... Maybe you could add a fallback option where reprlib.Repr.repr1() dispatches to some dunder method on the object (with the expectation that the object call back into repr1() when it wants to format a subobject)? That seems messy, since I usually think of dunder methods as belonging to the language rather than the standard library. But there is precedent for this sort of thing (e.g. __copy__ and __deepcopy__), so I suppose it could work.