[3.6] bpo-8722: Document getattr behavior with AttributeError in … · python/cpython@a8c25d1 (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 |
---|---|---|
@@ -1443,10 +1443,12 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances. | ||
1443 | 1443 | |
1444 | 1444 | .. method:: object.__getattr__(self, name) |
1445 | 1445 | |
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. | |
1450 | 1452 | |
1451 | 1453 | Note that if the attribute is found through the normal mechanism, |
1452 | 1454 | :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`. |