[Zope3-dev] Re: __contains__ and acquisition problem?

Florent Guillaume fg at nuxeo.com
Fri May 19 09:39:59 EDT 2006


On 19 May 2006, at 15:36, Jim Fulton wrote:
> Florent Guillaume wrote:
>> Jim, as the author of the Acquisition classes, could you comment  
>> on this?
>
> Uh, sure.  What does this have to do with Zope 3?

Well, I couldn't find a better list :)

> Anyway, the acquisition wrapper implementation hasn't been updated  
> to handle
> many slots that were added in recent years, including __contains__.

Ok, thanks.

Florent

>>> Could anybody shed some light on what's happening here:
>>>
>>>  >>> from Acquisition import Implicit
>>>
>>>  >>> class Impl(Implicit):
>>> ...     pass
>>>
>>>  >>> class C(Implicit):
>>> ...     def __getitem__(self, key):
>>> ...         print 'getitem', key
>>> ...         if key == 4:
>>> ...             raise IndexError
>>> ...         return key
>>> ...     def __contains__(self, key):
>>> ...         print 'contains', repr(key)
>>> ...         return key == 5
>>>
>>> The class by itself behaves as expected:
>>>
>>>  >>> c = C()
>>>  >>> 5 in c
>>> contains 5
>>> True
>>>  >>> 3 in c
>>> contains 3
>>> False
>>>
>>> Let's put c in the context of i:
>>>
>>>  >>> i = Impl()
>>>  >>> i.c = c
>>>
>>> Now why is the following happening? Why is __contains__ not used?
>>>
>>>  >>> 3 in i.c # c.__of__(i)
>>> getitem 0
>>> getitem 1
>>> getitem 2
>>> getitem 3
>>> True
>>>  >>> 5 in i.c
>>> getitem 0
>>> getitem 1
>>> getitem 2
>>> getitem 3
>>> getitem 4
>>> False
>>>
>
>
> -- 
> Jim Fulton           mailto:jim at zope.com       Python Powered!
> CTO                  (540) 361-1714            http://www.python.org
> Zope Corporation     http://www.zope.com       http://www.zope.org

-- 
Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com




More information about the Zope3-dev mailing list