[issue13667] __contains__ method behavior
João Bernardo
report at bugs.python.org
Wed Dec 28 17:58:29 CET 2011
João Bernardo <jbvsmo at gmail.com> added the comment:
I see that every other comparison operator (<, >, <=, >=, ==, !=) except for `is` work the way I expect and is able to return anything.
e.g.
>>> numpy.arange(5) < 3
array([ True, True, True, False, False], dtype=bool)
I didn't checked the code (and probably I'm talking nonsense), but seems like the `in` operator has an extra call to `PyObject_IsTrue` that maybe could be dropped?
Of course it can break code relying on `x in y` being True/False but it would only happen on customized classes.
Another option that won't break code is to add a different method to handle these cases. Something like "__contains_non_bool__", but that'd be a big api change.
----------
components: -Documentation
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13667>
_______________________________________
More information about the Python-bugs-list
mailing list