[Python-ideas] Compact repr operator (i.e., __short_repr__)
Michael Selik
mike at selik.org
Mon Feb 8 19:28:30 EST 2016
On Mon, Feb 8, 2016 at 6:36 PM Mahmoud Hashemi <mahmoud at hatnote.com> wrote:
> Without something like this, there's no way to ask an object if it's repr
> is of manageable length, or how its repr could be meaningfully shortened.
> Usually I just chop out the middle and add an ellipsis, but as for the time
> spent generating that middle, I'll never get those cycles back.
>
With the addition of ``__short_repr__`` would there be a change to the
default Python REPL? If not, how would you use the new magic method? If so,
then why not just change __repr__ for all the built-ins to truncate
automatically? As far as I know, reprs are not part of the backwards
compatibility guarantee. (Note, I'm not advocating for changing reprs.)
If the usage would be to write a function that checks for the existence of
__short_repr__, then why not simply move the implementation of ``if len(s)
< maxlen`` etc. to that function?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160209/080eebc6/attachment.html>
More information about the Python-ideas
mailing list