[Zope3-dev] ContextMethod / Wrapper questions...

Jim Fulton jim@zope.com
Fri, 27 Dec 2002 09:53:16 -0500


Steve Alexander wrote:
> Brian Lloyd wrote:
> 
...
>> The change would basically be:
>>
>>   - add ContextMethod descriptor type
> 
> 
> Don't do that. The current way of marking methods as being 
> ContextMethods by adding special markers to the method's dict has turned 
> out to be really useful. There are other method-like things, such as 
> bound ViewPageTemplateFiles that declare the same attributes, so that 
> they can be called with a context-wrapped self.

...

>>     These basically just check (efficiently) whether the     attr / 
>> slot implementation on the unwrapped object is     a context descriptor,
> 
> 
> So, rather than check for a context descriptor, check for the marker 
> attributes in the descriptor's dict.

This isn't quite right. We look for attributes on the descriptor.
We don't introspect the descriptor's dict.

So that means that every time we get a descriptor, we have to
do an attribute lookup.  This is a tad expensive.  I wish there
was an easier way to set this mark.

For example, if we *did* use a separate type, we could probably
spot it faster.

Like, we could have descriptor proxies that could be easily spotted,
either by checking for a specific type or by checking the mro.


> 
>>     and if so passes the wrapped self rather than the stripped self.
> 
> 
> Ok. It would be really nice if a wrapper instance could somehow be 
> clever, and implement only those C-level slots that the object it wraps 
> implements. So, callable(foo) would work properly, and there won't be 
> any subtle surprises on whether __len__ or __nonzero__, or __iter__ or 
> __getitem__ get called for a wrapped object.
> 
> This works for __call__ and __getitem__ in the current python 
> implementation.
> 
> At the Sprintathon, I had a talk with Guido about how to go about doing 
> this. However, I don't speak much C, so the details escape me. Jim also 
> had a suggestion about this, and again, I didn't understand the details :-)

I really think that this is a lot of bother and not really worth it.

Jim

-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org