Skip to content

Commit b478c5e

Browse files
[3.12] gh-112331: Fix reference manual description of attribute lookup mechanics (gh-112375) (#112412)
1 parent 2199ceb commit b478c5e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Doc/reference/expressions.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,18 @@ An attribute reference is a primary followed by a period and a name:
816816

817817
The primary must evaluate to an object of a type that supports attribute
818818
references, which most objects do. This object is then asked to produce the
819-
attribute whose name is the identifier. This production can be customized by
820-
overriding the :meth:`__getattr__` method. If this attribute is not available,
821-
the exception :exc:`AttributeError` is raised. Otherwise, the type and value of
822-
the object produced is determined by the object. Multiple evaluations of the
823-
same attribute reference may yield different objects.
824-
819+
attribute whose name is the identifier. The type and value produced is
820+
determined by the object. Multiple evaluations of the same attribute
821+
reference may yield different objects.
822+
823+
This production can be customized by overriding the
824+
:meth:`~object.__getattribute__` method or the :meth:`~object.__getattr__`
825+
method. The :meth:`!__getattribute__` method is called first and either
826+
returns a value or raises :exc:`AttributeError` if the attribute is not
827+
available.
828+
829+
If an :exc:`AttributeError` is raised and the object has a :meth:`!__getattr__`
830+
method, that method is called as a fallback.
825831

826832
.. _subscriptions:
827833

0 commit comments

Comments
 (0)