[Ironpython-users] Problem with the "in" operator for

Ivan Pozdeev vano at mail.mipt.ru
Wed Jul 8 06:55:20 CEST 2015

> Hi,

> As far as I can see, the "in" operator should return true if any
> object in the enumerable is "equal" to the object given as reference:

Indeed, https://docs.python.org/2/reference/expressions.html#membership-test-details

 For the list and tuple types, x in y is true if and only if there
 exists an index i such that x == y[i] is true.

Now, to check if IronPython honors this.

> assert a in (a,), 'a is in (a,)'
> assert a in (b,), 'a is in (b,)' # this one fails...

> As far as I can see via breakpoints, the Equals methods of the
> objects are never actually called, except on the first assertion with the == operator.

My guess is it's cutting corners by comparing hashes instead.

Ivan Pozdeev

More information about the Ironpython-users mailing list