On Thu, Dec 17, 2009 at 04:59:12PM +0100, Thomas Lotze wrote:
> Martijn Faassen wrote:
> > Their behavior should be:
> > 
> > IFoo.adapt(context) raises LookupError, unless the context provides IFoo,
> > in which case it returns context.
> > 
> > IFoo.adapt(context, default=default) returns default unless context
> > provides IFoo, in which case it returns context.
> > 
> > IFoo.utility() raises LookupError.
> > 
> > IFoo.utility(default=default) returns default
> I think looking at that API explains why we have trouble with having stub
> methods defined by zope.interface: these methods contain enough
> information about component concepts to blur the distinction between
> zope.interface and zope.component, but they still lie about the actual
> method signature. In that sense, these stubs would be worse than
> zope.interface not documenting the methods at all.
> In my and Wolfgang's opinion, we can either have zope.interface implement
> methods with the real contract, which would mean defining the full
> concepts of the ZCA within zope.interface (if not their implementation),
> or not even have method stubs in zope.interface and leave the whole
> business of defining specialised uses of interfaces to other packages such
> as zope.component.

I like things to fail noisily and loudly unconfigured and give good
information about what's wrong.  So my preferred implementation of a
stub "utility" function on Interface is:

    def utility(default=None):
        """Lookup a utility for this interface.

        A utility is a ${long explanation of utility concept}.

        This method behaves like ${explanation of utility method contract}. 
        raise NotImplementedError("""No Utility lookup mechanism has been 
            If you wish to use utility lookups on interfaces, please configure a
            package that contains this mechanism. Packages known to
            implement this are:

I agree that this encodes in the zope.interface package concepts from
zope.component. I feel uncomfortable about that. But I feel more
uncomfortable with magic where it is impossible to find out what is
going on by reading the code.

Brian Sutherland
Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope )

Reply via email to