[Python-Dev] Should the default equality operator compare values instead of identities?

Michael Hudson mwh at python.net
Tue Nov 8 00:02:12 CET 2005


"Martin v. Löwis" <martin at v.loewis.de> writes:

> BJörn Lindqvist wrote:
>> How would the value equality operator deal with recursive objects?
>> 
>> class Foo:
>>     def __init__(self):
>>         self.foo = self
>> 
>> Seems to me that it would take atleast some special-casing to get
>> Foo() == Foo() to evalute to True in this case...
>
> This is sort-of supported today:
>
>  >>> a=[]
>  >>> a.append(a)
>  >>> b=[]
>  >>> b.append(b)
>  >>> a == b
> True

Uh, I think this changed in Python 2.4:

>>> a = []
>>> a.append(a)
>>> b = []
>>> b.append(b)
>>> a == b
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
RuntimeError: maximum recursion depth exceeded in cmp

Cheers,
mwh

-- 
  First of all, email me your AOL password as a security measure. You
  may find that won't be able to connect to the 'net for a while. This
  is normal. The next thing to do is turn your computer upside down
  and shake it to reboot it.                     -- Darren Tucker, asr


More information about the Python-Dev mailing list