[Zope-dev] Acquisition and method lookup: loosing acquisition context

Dieter Maurer dieter@handshake.de
Wed, 28 Aug 2002 23:37:30 +0200


Acquisition lookup for (ExtensionClass'es Python) methods is not done
through the standard "__of__" call but handled specially:

	      if (PyECMethod_Check(r) && PyECMethod_Self(r)==self->obj)
		ASSIGN(r,PyECMethod_New(r,OBJECT(self)));

As a consequence, the method's "im_self" is not fully acquisition wrapped.
Rather, the context is more or less stripped down.

I would find it more naturally, when (ExtensionClass'es Python)
methods conceptually had an "__of__" method that relays the context
to "im_self". The code above would then become:

	      if (PyECMethod_Check(r)) {
		 im_self= PyECMethod_Self(r);
		 if (has__of__(im_self)):
		    ASSIGN(r,PyECMethod_New(r,__of__(im_self,OBJECT(self))));
	      }

This could be optimized to:

	      if (PyECMethod_Check(r)) {
		 im_self= PyECMethod_Self(r);
		 if (im_self==self->obj)
		    ASSIGN(r,PyECMethod_New(r,OBJECT(self)));
		 else if (has__of__(im_self)):
		    ASSIGN(r,PyECMethod_New(r,__of__(im_self,OBJECT(self))));
	      }

But maybe, there is a reason for the special rule.


I am unhappy with the special method treatment because
my "References" product does not work as expected due to the leaking context.

Most applications using "getattr" to look up methods in other objects
will suffer from the same problem.


Dieter