Skip to content

Commit a8c25d1

Browse files
miss-islingtoncsabella
authored andcommitted
[3.6] bpo-8722: Document __getattr__ behavior with AttributeError in property (GH-5542)
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). (cherry picked from commit d1f3181) Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
1 parent 1c2b138 commit a8c25d1

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Doc/reference/datamodel.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,12 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
14431443
14441444
.. method:: object.__getattr__(self, name)
14451445

1446-
Called when an attribute lookup has not found the attribute in the usual places
1447-
(i.e. it is not an instance attribute nor is it found in the class tree for
1448-
``self``). ``name`` is the attribute name. This method should return the
1449-
(computed) attribute value or raise an :exc:`AttributeError` exception.
1446+
Called when the default attribute access fails with an :exc:`AttributeError`
1447+
(either :meth:`__getattribute__` raises an :exc:`AttributeError` because
1448+
*name* is not an instance attribute or an attribute in the class tree
1449+
for ``self``; or :meth:`__get__` of a *name* property raises
1450+
:exc:`AttributeError`). This method should either return the (computed)
1451+
attribute value or raise an :exc:`AttributeError` exception.
14501452

14511453
Note that if the attribute is found through the normal mechanism,
14521454
:meth:`__getattr__` is not called. (This is an intentional asymmetry between
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Document :meth:`__getattr__` behavior when property :meth:`get` method
2+
raises :exc:`AttributeError`.

0 commit comments

Comments
 (0)