Message150283
| Author |
JBernardo |
| Recipients |
JBernardo, docs@python |
| Date |
2011年12月28日.09:11:09 |
| SpamBayes Score |
2.0966208e-07 |
| Marked as misclassified |
No |
| Message-id |
<1325063470.58.0.871415984198.issue13667@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Hi, I'm working on a class which implements the __contains__ method but the way I would like it to work is by generating an object that will be evaluated later.
It'll return a custom object instead of True/False
class C:
def __contains__(self, x):
return "I will evaluate this thing later... Don't bother now"
but when I do:
>>> 1 in C()
True
It seems to evaluate the answer with bool!
Reading the docs (http://docs.python.org/py3k/reference/expressions.html#membership-test-details) It says:
"`x in y` is true if and only if `y.__contains__(x)` is true."
It looks like the docs doesn't match the code and the code is trying to mimic the behavior of lists/tuples where "x in y" is the same as
any(x is e or x == e for e in y)
and always yield True or False.
There is a reason why it is that way?
Thanks! |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2011年12月28日 09:11:10 | JBernardo | set | recipients:
+ JBernardo, docs@python |
| 2011年12月28日 09:11:10 | JBernardo | set | messageid: <1325063470.58.0.871415984198.issue13667@psf.upfronthosting.co.za> |
| 2011年12月28日 09:11:09 | JBernardo | link | issue13667 messages |
| 2011年12月28日 09:11:09 | JBernardo | create |
|