Re: Interfaces vs ZCA concepts

Martijn Faassen <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
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

_______________________________________________
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 )
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.