[Python-ideas] Unambiguous repr for recursive objects

Ben Finney ben+python at benfinney.id.au
Sat Dec 26 06:36:55 EST 2015


Nick Coghlan <ncoghlan at gmail.com> writes:

> To make this less abstract, here's a simple example:
>
>     >>> a = [1, 2]
>     >>> b = [a]
>     >>> a.append(b)
>     >>> a
>     [1, 2, [[...]]]
>     >>> b
>     [[1, 2, [...]]]
>
> With the first alternative, that becomes:
>
>     >>> a
>     [1, 2, [<...>]]
>     >>> b
>     [[1, 2, <...>]]

That clarifies it quite well. The fact ‘<...>’ is not valid syntax is an
improvement: it helps to signal this is a display for something that
can't be simply serialised.

The ‘<’, ‘>’ enclosing characters also have a nice symmetry with the
default representation of so many types.

+1 to change the representation of “recursive references” to ‘<...>’.

-- 
 \       “The surest way to corrupt a youth is to instruct him to hold |
  `\       in higher esteem those who think alike than those who think |
_o__)             differently.” —Friedrich Nietzsche, _The Dawn_, 1881 |
Ben Finney



More information about the Python-ideas mailing list