Re: Interfaces vs ZCA concepts

Marius Gedminas <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <20091217203223.GA20687@platonas>
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

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFLKpVWkVdEXeem148RAvIqAJ9RI2F1/BiY/AE/aqCG/Y17UWWGzwCfQZAs
6ouNOMvLk2/N1V0RRpjjNhk=
=vjId
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.