bpo-8722: Document __getattr__ behavior with AttributeError in property (GH-4754)

When `__getattr__` is implemented, attribute lookup will always fall back to that,
even if the initial failure comes from `__getattribute__` or a descriptor's `__get__`
method (including property methods).
This commit is contained in:
Cheryl Sabella 2018-02-04 21:03:22 -05:00 committed by Nick Coghlan
parent 05e806767b
commit d1f318105b
2 changed files with 8 additions and 4 deletions

View File

@ -1463,10 +1463,12 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
.. method:: object.__getattr__(self, name) .. method:: object.__getattr__(self, name)
Called when an attribute lookup has not found the attribute in the usual places Called when the default attribute access fails with an :exc:`AttributeError`
(i.e. it is not an instance attribute nor is it found in the class tree for (either :meth:`__getattribute__` raises an :exc:`AttributeError` because
``self``). ``name`` is the attribute name. This method should return the *name* is not an instance attribute or an attribute in the class tree
(computed) attribute value or raise an :exc:`AttributeError` exception. for ``self``; or :meth:`__get__` of a *name* property raises
:exc:`AttributeError`). This method should either return the (computed)
attribute value or raise an :exc:`AttributeError` exception.
Note that if the attribute is found through the normal mechanism, Note that if the attribute is found through the normal mechanism,
:meth:`__getattr__` is not called. (This is an intentional asymmetry between :meth:`__getattr__` is not called. (This is an intentional asymmetry between

View File

@ -0,0 +1,2 @@
Document :meth:`__getattr__` behavior when property :meth:`get` method
raises :exc:`AttributeError`.