[Zope-dev] Interfaces vs ZCA concepts

Martijn Faassen faassen at startifact.com
Thu Dec 17 06:53:13 EST 2009


Hey,

Tres Seaver wrote:
[snip]
> Any code today which wants a utility is calling 'getUtilty' (if it
> *knows* the utility must be registered) or 'queryUtility' (if it thinks
> it might not be).  Less facetiously than my first challenge: please
> point to actual code in the wild which looks like::
> 
>   try:
>       foo = getUtilty(IFoo, name='bar')
>   except ComponentLookupError:
>       # do something
> 
> instead of::
> 
>    foo = queryUtility(IFoo, name='bar')
>    if foo is None:
>        # do something
> 
> I will argue that any code doing the first, outside of maybe tests of
> the ZCA itself is plain broken.

I have code like that in the wild - I have no real reason why I didn't 
queryUtility, but I didn't think it mattered.

Why is it plain broken? Isn't getUtility supported to raise 
ComponentLookupError if it cannot find the required utility?

Regards,

Martijn



More information about the Zope-Dev mailing list