-----BEGIN PGP SIGNED MESSAGE-----
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
>>>> 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:
def getUtility(self, provided, name=u''):
utility = self.utilities.lookup((), provided, name)
if utility is None:
raise ComponentLookupError(provided, name)
def getAdapter(self, object, interface, name=u''):
adapter = self.adapters.queryAdapter(object, interface, name)
if adapter is None:
raise ComponentLookupError(object, interface, name)
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
$ 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')
# do something
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
Zope-Dev maillist - Zope-Dev@zope.org
** No cross posts or HTML encoding! **
(Related lists -