[Zope-dev] Interfaces vs ZCA concepts

Marius Gedminas marius at gedmin.as
Thu Dec 17 15:32:23 EST 2009


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20091217/816fca53/attachment.bin 


More information about the Zope-Dev mailing list