<div dir="ltr">I'm curious why the return value of __contains__ is coerced to True or False, whereas the return value of "normal" comparison operators like __lt__ and the like are not. The latter return the value directly without forcing it to be True or False. <div>
<br></div><div>This makes overriding __contains__ significantly less flexible, so I'm wondering why it's designed or implemented that way. (I believe it's the cmp_outcome() function in Python/ceval.c that does this: <a href="http://hg.python.org/cpython/file/db9fe49069ed/Python/ceval.c#l4545">http://hg.python.org/cpython/file/db9fe49069ed/Python/ceval.c#l4545</a>)</div>
<div><div><div><br></div></div></div><div>For example, the "peewee" ORM overloads __lt__ and the like so it can map Python expressions to SQL. But it can't do this with the "in" operator due to the result of "x in y" always returning True or False in Python. So it (ab)uses the "<<" operator to do this instead (See the peewee docs at <a href="http://peewee.readthedocs.org/en/latest/peewee/querying.html#column-lookups">http://peewee.readthedocs.org/en/latest/peewee/querying.html#column-lookups</a>).</div>
<div><br></div><div>I'm sure there's a good reason for why "in" is different here, but I can't see why right now.</div><div><br></div><div>-Ben</div></div>