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

Florent Guillaume fg at nuxeo.com
Fri Jun 2 10:36:48 EDT 2006


Ok I fixed this for Zope 2.10 and trunk:

http://svn.zope.org/?view=rev&rev=68459

Florent


Jim Fulton wrote:
> Anyway, the acquisition wrapper implementation hasn't been updated to 
> handle
> many slots that were added in recent years, including __contains__.
> 
> Jim
> 
>> Florent Guillaume wrote:
>>
>>> 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
>>>
>>
>>
> 
> 


-- 
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 Zope-Dev mailing list