Roundtrippable reprs are certainly part of Python canon, whether or not they are universally used (Chris), or guaranteed (Mike).

I could see __short_repr__ (and associated reprlib) being the desired behavior in some console environments, but I'm not one to say it should be the default in the main Python REPL.

My use cases are for 1) a web based console/REPL and 2) a configuration store that maintains a human readable history of past values (i.e., it does not maintain references to the objects themselves).

But mostly I wanted to kick off the discussion of how to update reprlib (and pprint) to be more efficient and applicable.

Mahmoud



On Mon, Feb 8, 2016 at 4:28 PM, Michael Selik <mike@selik.org> wrote:
On Mon, Feb 8, 2016 at 6:36 PM Mahmoud Hashemi <mahmoud@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?