[3.7] bpo-8722: Document __getattr__ behavior with AttributeError in … · python/cpython@fea0a12

File tree

2 files changed

lines changed

  • Misc/NEWS.d/next/Documentation

2 files changed

lines changed

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

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`.