[Zope-dev] Acquisition muddleness solved!

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Thu, 22 Feb 2001 10:31:42 +1100


richard@bizarsoftware.com.au wrote:
> A simple enough scenario:
> Python 1.5.2 (#1, Sep 30 2000, 18:08:36)  [GCC 2.95.3 19991030
> (prerelease)] on linux-i386
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import ExtensionClass
> >>> import Acquisition
> >>> class A(ExtensionClass.Base):
> ...  def foo(self):
> ...   print repr(self), type(self)
> ...
> >>> class B(Acquisition.Implicit):
> ...  pass
> ...
> >>> a=A()
> >>> print repr(a), type(a)
> <A instance at 80ec588> <extension class __main__.A at 80eb1e0>
> >>> a.b=B()
> >>> print repr(a.b), type(a.b)
> <B instance at 80dc9c0> <extension class
> Acquisition.ImplicitAcquirerWrapper at 401460e0>
> >>> a.b.foo()
> <A instance at 80ec588> <extension class __main__.A at 80eb1e0>
> 
> Now, I would've expected to see a.b.foo() print out exactly the same
> information as repr(a.b), type(a.b). In fact, I even scrounged up the
> Acquisition doc (it really isn't that easy to find these days...) and I can
> quote from it in support of what I believe should be happening:
> 
> '''
>   Acquisition and methods
> 
>     Python methods of objects that support acquisition can use
>     acquired attributes as in the 'report' method of the first example
>     above.  When a Python method is called on an object that is
>     wrapped by an acquisition wrapper, the wrapper is passed to the
>     method as the first argument.  This rule also applies to
>     user-defined method types and to C methods defined in pure mix-in
>     classes.
> '''

OK, I figured it out. The method foo requires an instance of A to work, and
a.b isn't one, but a is.

Makes life a little more difficult, but at least we know how it works now.


    Richard

-- 
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)