[Zope3-dev] Re: __contains__ and acquisition problem?
Florent Guillaume
fg at nuxeo.com
Fri May 19 09:24:35 EDT 2006
Jim, as the author of the Acquisition classes, could you comment on this?
Thanks,
Florent
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 Zope3-dev
mailing list