[Python-Dev] Should the default equality operator compare values instead of identities?
Ronald Oussoren
ronaldoussoren at mac.com
Tue Nov 8 08:37:16 CET 2005
On 7-nov-2005, at 23:34, Martin v. Löwis wrote:
> 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:
But only for lists ;-)
>>> a = {}
>>> a[1] = a
>>>
>>> b = {}
>>> b[1] = b
>>>
>>> a == b
Traceback (most recent call last):
File "<stdin>", line 1, in ?
RuntimeError: maximum recursion depth exceeded in cmp
>>>
>
>>>> a=[]
>>>> a.append(a)
>>>> b=[]
>>>> b.append(b)
>>>> a == b
> True
>
> Regards,
> Martin
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/
> ronaldoussoren%40mac.com
More information about the Python-Dev
mailing list