[IronPython] Lists of instances of classes

William Reade william at resolversystems.com
Thu Jan 5 12:33:29 CET 2006


It appears that tuples have similar problems to lists (tested on 0.9.5 
and 1.0b1):

----------
 >>> class C:
...   pass
...
 >>> c1 = C()
 >>> c2 = C()
 >>> (c1, c2) == (c2, c1)
True
----------

Cheers
William

Giles Thomas wrote:

>Some more discoveries, following on from the below:
>
>---------------
> >>> class D:
>...   pass
>...
> >>> d1 = D()
> >>> [c1, c2, c1] == [c1, c2, d1]
>True
> >>> class E:
>...   def __init__(self):
>...     pass
>...
> >>> e1 = E()
> >>> [c1, c2, c1] == [c1, c2, e1]
>True
> >>> e1.foo = "bar"
> >>> [c1, c2, c1] == [c1, c2, e1]
>True
>---------------
>
>Looks like it's just assuming all objects are identical.
>
>
>Regards,
>
>Giles
>
>
>Giles Thomas wrote:
>  
>
>>Hi,
>>
>>We've found what looks like a bug in list comparison:
>>
>>---------------
>>IronPython 1.0.2190 (Beta) on .NET 2.0.50727.42
>>Copyright (c) Microsoft Corporation. All rights reserved.
>> >>> class C:
>>...   pass
>>...
>> >>> c1 = C()
>> >>> c2 = C()
>> >>> [c1, c2] == [c2, c1]
>>True
>> >>> [c1] == [c2]
>>True
>> >>> c1 == c2
>>False
>> >>>
>>-----------------
>>
>>Confirmed in 0.9.5, 0.9.6, and 1.0.2190
>>
>>There is a horrible hack to work around it:
>>
>>-----------------
>> >>> str([c1, c2]) == str([c2, c1])
>>False
>>-----------------
>>
>>
>>Cheers,
>>
>>Giles
>>
>>    
>>
>_______________________________________________
>users mailing list
>users at lists.ironpython.com
>http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>  
>




More information about the Ironpython-users mailing list