[3.7] bpo-8722: Document getattr behavior with AttributeError in … · python/cpython@fea0a12 (original) (raw)
File tree
2 files changed
lines changed
- Misc/NEWS.d/next/Documentation
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1463,10 +1463,12 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances. | ||
1463 | 1463 | |
1464 | 1464 | .. method:: object.__getattr__(self, name) |
1465 | 1465 | |
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. | |
1470 | 1472 | |
1471 | 1473 | Note that if the attribute is found through the normal mechanism, |
1472 | 1474 | :meth:`__getattr__` is not called. (This is an intentional asymmetry between |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | +Document :meth:`__getattr__` behavior when property :meth:`get` method | |
2 | +raises :exc:`AttributeError`. |