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   [EMAIL PROTECTED]



_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to