repr(x) == repr(y) <=> x == y AND eval(repr(x)) == x

Tim Peters tim.one at comcast.net
Fri Oct 18 22:36:47 CEST 2002


[Thorsten Kampe]
> ...
> This relies on two assumptions:
>
> 1. repr(x) == repr(y) <=> x == y

You'll be deluged with counterexamples soon enough <wink>, so I'll just give
you a surprising one:  this can fail if x and y are ordinary dicts, with x
== y.  The order in which keys are listed isn't defined, and if the the same
set of key+value pairs is inserted into two dicts but in different orders,
internal key collisions can cause different orders internally too (which
repr() then reveals).  It isn't possible to give a specific example that
will fail across all versions of Python, though, because nothing is defined
about this internal order, and it can (and does!) vary across releases.





More information about the Python-list mailing list