[Python-Dev] Attribute lookup ambiguity
Pascal Chambon
chambon.pascal at wanadoo.fr
Tue Mar 23 21:57:22 CET 2010
Greg Ewing a écrit :
>
> Pascal Chambon wrote:
>
>> I don't follow you there - in my mind, the default __getattribute__
>> could simply have wrapped all its operations inside soem kind of
>> "try..catch AttributeError:" mechanism, and thus been able to
>> fallback to __getattr__ in any way.
>
> But then it would be incorrect to say that "__getattribute__
> raises an exception".
>
> When we say that a function raises an exception, we normally
> mean that the exception propagates out of the function and
> can be seen by the caller, not that it was raised and caught
> somewhere inside the function.
>
Indeed, but I've never run into any doc mentionning that the default
__getattribute__ raised in exception instead of forwarding to
__getattr__ by itself.
All I've found is "If the class also defines __getattr__()
<http://docs.python.org/reference/datamodel.html#object.__getattr__>,
the latter will not be called unless __getattribute__()
<http://docs.python.org/reference/datamodel.html#object.__getattribute__>
either calls it explicitly or raises an AttributeError
<http://docs.python.org/library/exceptions.html#exceptions.AttributeError>";
that sentence which simply offers two alternatives for the behaviour of
customized __gettattribute__ methods, without giving any hint on the
behaviourthat was chosen when implementing object.__gettattribute__.
Or am I missing some other doc which I'm supposed to know :?
"In the face of ambiguity, refuse the temptation to guess", as we say
anyway, so I propose we patch the doc to clarify this point for newcomers ^^
Regards,
Pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100323/088e9338/attachment.html>
More information about the Python-Dev
mailing list