[Python-ideas] reprs of recursive datastructures.

Terry Reedy tjreedy at udel.edu
Sat Sep 8 21:02:23 CEST 2012

On 9/8/2012 6:02 AM, Nick Coghlan wrote:
> On Sat, Sep 8, 2012 at 7:49 PM, Guido van Rossum <guido at python.org> wrote:
>> To what purpose? I still don't understand what the actual use case is
>> where you think that will produce a better experience for the user.
> The thing I don't like is that the current display flat out lies about
> the sequence contents - it displays a terminal constant ("..."),
> rather than a clear marker that a recursive loop was detected.
> The case of multiple references to a different list is not the same,
> as then the repr() at least still accurately reflects what you would
> get when iterating over the data structure.
> So, my perspective is if attempting to naively flatten the list would
> create an infinite loop, then I want evaluating the representation to
> throw a syntax error the way it did in Python 2.

This expresses what I was trying to say better than I did. When '...' 
was chosen for recursive structures, it make the result not-legal-code, 
as it should be. The 3.0 incorporation of '...' as legal syntax, 
created, in a sense, a reversion. So that suggests revising the 
recursion marker.

That said, there is the issue of doctests, so I would only change in 3.4.

Terry Jan Reedy

More information about the Python-ideas mailing list