Hash: SHA1

Martin Aspeli wrote:
> Tres Seaver wrote:
>>>> * The hook invokes the `query*` functions to play nice with any other
>>>>    component hooks and the interface methods raise a TypeError if all of 
>>>> them
>>>>    fail to find a component.
>>> A TypeError instead of a ComponentLookupError?
>>> I was thinking we should keep the behavior as close to zope.component as
>>> we can, including ComponentLookupError. Don't you get a
>>> ComponentLookupError with the classic adapter hook too? So I'm -1 to
>>> making this a TypeError.
>> +1 to TypeError:  nobody really cares about the type of the error:  code
>> that wants to be robust about a failure uses the 'query' methods.  As
>> long as the message is informative enough (which ComponentLookupError
>> isn't, really) we should be fine.  If we made CLE derive from TypeError,
>> we could even still be satisfying the contract.
> zope.component raises TypeError if you can't adapt. It raises 
> ComponentLookupError it can't find a utility.

Not so:  see $ZSVN/zope.component/trunk/src/zope/component/registry.py:

  class Components:
      def getUtility(self, provided, name=u''):
          utility = self.utilities.lookup((), provided, name)
          if utility is None:
              raise ComponentLookupError(provided, name)
          return utility
      def getAdapter(self, object, interface, name=u''):
          adapter = self.adapters.queryAdapter(object, interface, name)
          if adapter is None:
              raise ComponentLookupError(object, interface, name)
          return adapter

which matches the contract spelled out in the docstrings for IComponent.
 That class raises TypeError only for invalid values passed to the
various registration functions.

At any rate, we are talking about errors raised from zope.itnerface
APIs, which nowhere mention or use CLE::

 $ svn info .  | grep URL
 URL: svn+ssh://svn.zope.org/repos/main/zope.interface/trunk
 $ svn up
 At revision 106615.
 $ find . -name "*.py" |  xargs grep ComponentLookupError

Nobody calling an interface today has any *defined* behavior to expect
in the case of failure (in fact, '__call__' is not even part of IInterface!)

> Let's keep exceptions the same. People do catch specific errors, so 
> those who've done 'except TypeError' now aren't going to be happy if we 
> change that to something else when they try to move to use the "new" API.

Please point to existing code which calls 'IFoo.utility(name="bar")' and
catches a CLE.  Since this is a new API we are talkign about, there
can't be any BBB concerns.

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::

      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.

- --
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope )

Reply via email to