[Zope3-dev] Proposal: Improving on __implements__

Steve Alexander steve@cat-box.net
Sun, 19 Jan 2003 11:15:32 +0200


> Just a comment on the implementation...  if you manipulate f_locals, you 
> can just use the function to *set* (or change) an __implements__ value.  
> AFAIK, class body code is executed with an actual local dictionary, so 
> it should be modifiable.  Thus, there's no need for a registry and all 
> that other sort of thing.  In fact, you don't even need to care about 
> the class name.

You're right. It works. Thanks. I'll amend the proposal.

However, I still need the registry to make declarations for builtin 
classes and other classes where the class object itself is immutable.


> While in some ways, this is "more" magical, it's a simpler 
> implementation.  I'm not sure how Jython is affected, but then I'm not 
> sure whether Jython allows you to get at Python stack frames in the 
> first place.

In my proposal, I'm not intending to get rid of the semantics of 
'implements' that you cite below: implements(cls, interface)

...although it might need to have a different name to distinguish it 
from the new 'magic' implements.

So if the 'magic' implements won't work with Jython, it will be possible 
to fall back on the 'registry' method, or rewrite code to use the 
'implements(cls, interface)' function.


> While I do like the simplified syntax, I'm also not sure that it does 
> anything that you can't do like this:
> 
> class ServiceSubscriberEventChannel(SubscriptionTracker, EventChannel):
>     """An event channel that wants to subscribe to the nearest
>     event service when bound, and unsubscribe when unbound.
>     """
> 
> implements(ServiceSubscriberEventChannel,
>     (IBindingAware, EventChannel.__implements__, 
> SubscriptionTracker.__Implements__)
> )

I'd rather spell this as below, to get rid of the class.__implements__:

   declareImplements(ServiceSubscriberEventChannel, IBindingAware)
   declareImplementsLike(ServiceSubscriberEventChannel,
                         EventChannel, SubscriptionTracker)


I'd like to remove all reference to an '__implements__' attribute from 
regular code.

> While it's nice to put it in the class body, I'm not sure it's worth the 
> magic.  So I'm +0 on it.

Thanks for the feedback.

--
Steve Alexander