On Wed, Dec 16, 2009 at 04:48:06PM -0500, Tres Seaver wrote:
There is a perfectly reasonable "default" implementation anyway (in the absence of any hooks):
- 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 would much rather keep a "hook registration" API in the interface class for these methods than obscure their origin semantics via a monkey patch.
I'll throw this into the pot for your contemplation: I probably wasted many hours during my first several years of Zope 3 development, trying to figure out why zope.schema.Choice fields wouldn't find my IVocabularyFactory utilities I was registering right here in the test's setUp, and why I had to use some strange VocabularyRegistries instead of mechanically converting ZCML directives into provideAdapter statements. Until I discovered one day that just by *importing* a module (specifically, zope.app.component.vocabulary) I get a side-effect of replacing one vocabulary mechanism with another one. So I'm -99 for magical side effects of import statements, but thankfully the community opinion is already against them. I'm -0 for having an implementation that seems to be working, but isn't (utility lookup when no utilities can possibly be defined? very useful, that), unless you invoke some magical incantation. It's only -0 rather than something stronger because the same sort of situation already exists with Interface.__call__ hook, and it doesn't cause any problems in practice (probably because everybody calls placelessSetUp() at the start of their test setUp). Marius Gedminas -- http://pov.lt/ -- Zope 3 consulting and development