[Zope-dev] A summary of "Interfaces vs ZCA concepts"

Martijn Faassen faassen at startifact.com
Fri Dec 18 11:23:04 EST 2009


Ethan Jucovy wrote:
> +1 from my perspective of "I don't know or understand the core ZCA
> codebase very well (and don't understand all the implications in this
> discussion) but often read or trace through the code."  A
> well-documented NotImplementedError seems much more human-useful than
> a default implementation that fulfills the contract, because it
> assertively announces the expectation for the most common case by far:
> "you probably want to plug in a real implementation here."  Then if
> there is a need for the proposed default implementation, it can be
> provided as a plugin by some other package, right?

I'm now convinced people want to see a clear NotImplementedError.

I think if we went with a plugin structure, we could do something like this:

class Interface:
     ...
     def utility(...):
        return lookup_plugin.utility(...)

class NotImplementedLookupPlugin(object):
     def utility(...):
         raise NotImplementedError("""
this is the not implemented lookup plugin. You need to install another 
one. Blah blah zope.component blah blah""")

lookup_plugin = NotImplementedLookupPlugin()

def set_lookup_plugin(plugin):
     global lookup_plugin
     lookup_plugin = plugin

As long as external packages do not register a proper plugin, it'll 
raise NotImplementedErrors. Both the actual error as well as the name of 
the default lookup plugin signal something hasn't been installed.

We could also easily provide *another* plugin in zope.interface that 
does the "as if the registry is empty" behavior, if that turns out to be 
useful (perhaps for testing). But to use it someone would need to 
explicitly enable it. Tests could also define fake lookup plugins with 
other behavior so we can test these methods properly.

Regards,

Martijn



More information about the Zope-Dev mailing list