[IronPython] Re: A little bug about "in" operator
Timothy Fitz
firemoth at gmail.com
Wed Oct 20 23:59:52 CEST 2004
[谭 颖华]
> >>> t = (1,2,3)
> >>> t
> (1,2,3)
> >>> 2 in t
> True
> >>> 5 in t
> False
> >>> 's' in t
> True
I think Line 329 of Object\Ops.cs should test for support of the
ISequence interface.
public static object In(object x, object y) {
if (y is IDictionary) {
return bool2object(((IDictionary)y).Contains(x));
} else if (y is IList) {
return bool2object( ((IList)y).Contains(x) );
} else if (y is ISequence) {
return ((ISequence)y).__contains__(x);
} else {
IEnumerator e = GetEnumerator(y);
while (e.MoveNext()) {
if (Ops.IsTrue(Ops.Equal(e.Current, x))) return TRUE;
}
return FALSE;
}
}
Unfortunately, this leads to the conclusion that the fallback code
here isn't working. On further inspection, Ops.Equal is returning
Ops.NotImplemented, which is actually a string. A string tests true.
The ISequence fix rids you of the tuple problem, however A:
Ops.NotImplemented should be a class, and B: IntOps.Equals should
handle the string case in some way or another.
More information about the Ironpython-users
mailing list