[Zope3-dev] ConextMethod confusion

Steve Alexander steve@cat-box.net
Tue, 03 Dec 2002 23:01:32 +0000


> There are two confusing things about the current implementation.  The
> first is that there is a module named SimpleMethodWrapper.  I find
> this confusing because 1) the objects in it don't wrap methods and 2)
> Python has a builtin method-wrapper that does wrap methods.  It
> appears that SimpleMethodWrapper wraps an object so that something
> special happens to some method lookups.
> 
> I'm not sure what a better name would be perhaps just SimpleWrapper or
> Wrapper?  The fact that the module lives in Zope.ContextMethod gives
> some indication of its purposes without putting the "Method" decoy in
> its name.

It is called "SimpleMethodWrapper" because:

   Simple: it takes an approach to rebinding methods that was originally
           considered way too simple, using markers on methods rather
           than full-blown custom method-descriptors.

   Method: its job is to rebind methods.

   Wrapper: it is a wrapper.

I better name would be "RebindingWrapper" or "MethodRebindingWrapper".


>>from wrapper import *

Import the functions that allow python code to inspect context wrappers.

I'll make this explicit.


>>from SimpleMethodWrapper import wrapperCreator as Wrapper

We found that we needed to use different wrappers, depending on whether 
the object in question is callable or not.
This code was never refactored, because we expect it to be reimplemented 
in C in the near future.


> It's also confusing that the import * defines a Wrapper which is
> immediately overridden by another import of Wrapper which is defined
> by something that isn't even call Wrapper.  What names is the import *
> actually trying to put in the namespace?  Perhaps clients should get
> those names explicitly via Zope.ContextMethod.wrapper?

The Wrapper package provides these functions. It isn't the business of 
clients to look inside the package, or worry about how they are provided 
:)  Maybe we need an interface for this.

> I also think
> the name in SimpleMethodWrapper should match the name in __init__.
> Can it be renamed to Wrapper in SimpleMethodWrapper?  If it can't, I
> think that just illustrates why it is so confusing :-).

It could be. However, it is a factory function, masquerading as a type 
factory, for the limited purposes for which that factory is used in code.

So, in general response to all of the above, the package sucks somewhat, 
although it does kindof work well enough at present. You're right that 
it probably should be refactored. Actually, various things about the 
whole Zope 3 approach to security and context-wrapping proxies needs a 
fresh look, and a touch of refactoring. Perhaps we'll look at this at or 
after the Vilnius sprint.

--
Steve Alexander