[Zope3-dev] Re: Proposal: Improving on __implements__

Yuppie schubbe@web.de
Mon, 20 Jan 2003 00:01:09 +0100


Steve Alexander wrote:
> class ServiceSubscriberEventChannel(SubscriptionTracker, EventChannel):
>     """An event channel that wants to subscribe to the nearest
>     event service when bound, and unsubscribe when unbound.
>     """
> 
>     __implements__ = (
>         EventChannel.__implements__,
>         SubscriptionTracker.__implements__,
>         IBindingAware
>         )

Writing code like this (in Zope2) I always had the impression there is 
something wrong with the syntax:

Normally I use a superclass because I want to use its interface 
implementation. Why do I have to add explicitly the inherited interfaces 
to the declaration?

But __implements__ is a simple attribute, so I have to add them 
explicitly anyway.

> Becomes this:
> 
> from zope.interface import implements, implementsLike
> 
> class ServiceSubscriberEventChannel(SubscriptionTracker, EventChannel):
>     """An event channel that wants to subscribe to the nearest
>     event service when bound, and unsubscribe when unbound.
>     """
> 
>     implementsLike(EventChannel, SubscriptionTracker)
>     implements(IBindingAware)

implements() is a function and could do implicit what implementsLike() 
does in your example explicit. I'd prefer a syntax like this:


from zope.interface import addImplements

class ServiceSubscriberEventChannel(SubscriptionTracker, EventChannel):
     """An event channel that wants to subscribe to the nearest
     event service when bound, and unsubscribe when unbound.
     """

     addImplements(IBindingAware)



Just my 2 cents.
Cheers,

Yuppie