Skip to content

Commit fea0a12

Browse files
miss-islingtoncsabella
authored andcommitted
[3.7] bpo-8722: Document __getattr__ behavior with AttributeError in property (GH-5543)
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 <[email protected]>
1 parent 4abcbc0 commit fea0a12

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

‎Doc/reference/datamodel.rst‎

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

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

14711473
Note that if the attribute is found through the normal mechanism,
14721474
: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)