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?

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

Jim

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





--
Jim Fulton           mailto:[EMAIL PROTECTED]       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org
_______________________________________________
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