[Python-ideas] reprs of recursive datastructures.

Steven D'Aprano steve at pearwood.info
Sat Sep 8 10:06:41 CEST 2012

On 08/09/12 17:23, Terry Reedy wrote:

> In particular, the representations of recursive lists use what is
>now the Ellipsis literal '...', so they are also valid list displays
>for a non-recursive nested list containing Ellipsis. The interpreter
>always reads ... as the Ellipsis literal, which it nearly always is
>not what is meant.

I'm not sure that you are right to assume that recursive lists are
more common than lists containing Ellipsis. Neither are exactly common,
and at least a few people use Ellipsis as a ready-made sentinel value
that isn't None.

> It would be trivial to tweak the representations of recursive lists
>so they are not valid list displays.

Ah, I had not realised that you wanted eval(repr(x)) to fail if x was
recursive. That's more reasonable than expecting it to generate x.

Changing the repr of recursive lists will break doctests.

And frankly, my aesthetic sense would be hurt if the repr of a
recursive list used something other than ... for the part not displayed.
An ellipsis is the right symbol to use when skipping part of the
display, and an ellipsis is three dots, not two or four. A unicode …
would be acceptable, except I understand that buildins must be ASCII.

I don't think this is genuinely enough of a problem that it needs fixing.


More information about the Python-ideas mailing list