On Sep 4, 2012, at 11:32 AM, Eric Lemoine wrote:

> On Tue, Sep 4, 2012 at 5:30 PM, Michael Bayer <mike...@zzzcomputing.com> 
> wrote:
>> 
>> On Sep 4, 2012, at 11:24 AM, Eric Lemoine wrote:
>> 
>>> On Tue, Sep 4, 2012 at 5:20 PM, Eric Lemoine
>>> <eric.lemo...@camptocamp.com> wrote:
>>>> 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.
>>> 
>>> 
>>> 
>>> Actually, I was referring to "contains", not "__contains__".
>> 
>> that should just work out of the gate.  There's an "escape" kw you need to 
>> ignore as it loops around, otherwise works:
>> 
>>    def test_contains(self):
>>        class MyType(UserDefinedType):
>>            class comparator_factory(UserDefinedType.Comparator):
>>                def contains(self, other, **kw):
>>                    return self.op("->")(other)
>> 
>>        self.assert_compile(
>>            Column('x', MyType()).contains(5),
>>            "x -> :x_1"
>>        )
> 
> Ok I just didn't have **kw. I'm wondering if I should add it to all of
> my comparator functions.

well to the non-underscored names, it should be harmless.  the underscored 
names are Python API and won't change.


-- 
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