On Tue, Sep 4, 2012 at 5:18 PM, Michael Bayer <mike...@zzzcomputing.com> wrote:
> can't do __contains__ due to Python behavior:
>
> class Foo(object):
>     def __add__(self, other):
>         return (self, "add", other)
>
>     def __contains__(self, other):
>         return (self, "contains", other)
>
> f1 = Foo()
>
> assert f1 + 5 == (f1, "add", 5)
>
> assert 5 in f1 == (f1, "contains", 5), 5 in f1
>
> second assertion fails, it forces a bool() on the result.   __nonzero__() is 
> required to return True/False/int, I suppose we could make a custom int 
> subclass but that's getting really weird.


Oh right. Thanks for the explanation.




-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemo...@camptocamp.com
http://www.camptocamp.com

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to