From 07f968d62a3fdea7c3882a81ea71cb596483e9ce Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 24 Nov 2023 09:36:40 -0600 Subject: [PATCH 1/6] gh-112331: Fix reference manual description of attribute lookup mechanics --- Doc/reference/expressions.rst | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 14c2afa15ad7fb9..e5112d82ca28048 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -823,12 +823,17 @@ An attribute reference is a primary followed by a period and a name: The primary must evaluate to an object of a type that supports attribute references, which most objects do. This object is then asked to produce the -attribute whose name is the identifier. This production can be customized by -overriding the :meth:`__getattr__` method. If this attribute is not available, -the exception :exc:`AttributeError` is raised. Otherwise, the type and value of -the object produced is determined by the object. Multiple evaluations of the -same attribute reference may yield different objects. +attribute whose name is the identifier. The type and value produced is +determined by the object. Multiple evaluations of the same attribute +reference may yield different objects. +This production can be customized by overriding the :meth:`__getattribute__` +method or the :meth:`__getattr__` method. The :meth:`__getattribute__` +is called first and either returns a value or raises :exc:`AttributeError` +if the attribute is not available. + +If an :exc:`AttributeError` raised and the object has a :meth:`__getattr__` +method, that method is called as a fallback. .. _subscriptions: From 43e3a2c58dce34c03025941467ff1dcf7aa1fe5b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 24 Nov 2023 09:48:16 -0600 Subject: [PATCH 2/6] Add ~object links --- Doc/reference/expressions.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index e5112d82ca28048..c868482f55cc56a 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -827,13 +827,13 @@ attribute whose name is the identifier. The type and value produced is determined by the object. Multiple evaluations of the same attribute reference may yield different objects. -This production can be customized by overriding the :meth:`__getattribute__` -method or the :meth:`__getattr__` method. The :meth:`__getattribute__` -is called first and either returns a value or raises :exc:`AttributeError` -if the attribute is not available. +This production can be customized by overriding the +:meth:`~object.__getattribute__` method or the :meth:`__getattr__` method. +The :meth:`__getattribute__` method is called first and either returns a value +or raises :exc:`AttributeError` if the attribute is not available. -If an :exc:`AttributeError` raised and the object has a :meth:`__getattr__` -method, that method is called as a fallback. +If an :exc:`AttributeError` raised and the object has a +:meth:`~object.__getattr__` method, that method is called as a fallback. .. _subscriptions: From cf24384b03e7564a500ba6125cba11f146101b28 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 24 Nov 2023 09:55:56 -0600 Subject: [PATCH 3/6] Put the ~object link only in the first reference. --- Doc/reference/expressions.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index c868482f55cc56a..33067b5d73189ed 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -828,12 +828,13 @@ determined by the object. Multiple evaluations of the same attribute reference may yield different objects. This production can be customized by overriding the -:meth:`~object.__getattribute__` method or the :meth:`__getattr__` method. -The :meth:`__getattribute__` method is called first and either returns a value -or raises :exc:`AttributeError` if the attribute is not available. +:meth:`~object.__getattribute__` method or the :meth:`~object.__getattr__` +method. The :meth:`__getattribute__` method is called first and either +returns a value or raises :exc:`AttributeError` if the attribute is not +available. -If an :exc:`AttributeError` raised and the object has a -:meth:`~object.__getattr__` method, that method is called as a fallback. +If an :exc:`AttributeError` raised and the object has a :meth:`__getattr__` +method, that method is called as a fallback. .. _subscriptions: From 3bace811c9a77f6ba5ab65e2dfe4d29dea80979d Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 24 Nov 2023 10:04:55 -0600 Subject: [PATCH 4/6] Missing verb --- Doc/reference/expressions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 33067b5d73189ed..c68941ce9bc5a13 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -833,7 +833,7 @@ method. The :meth:`__getattribute__` method is called first and either returns a value or raises :exc:`AttributeError` if the attribute is not available. -If an :exc:`AttributeError` raised and the object has a :meth:`__getattr__` +If an :exc:`AttributeError` is raised and the object has a :meth:`__getattr__` method, that method is called as a fallback. .. _subscriptions: From 6a4be55779309a0ea84f9ad6868c026fb9de625b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 25 Nov 2023 00:25:26 -0600 Subject: [PATCH 5/6] Update Doc/reference/expressions.rst Co-authored-by: Alex Waygood --- Doc/reference/expressions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index c68941ce9bc5a13..535c5d2ced03c12 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -833,7 +833,7 @@ method. The :meth:`__getattribute__` method is called first and either returns a value or raises :exc:`AttributeError` if the attribute is not available. -If an :exc:`AttributeError` is raised and the object has a :meth:`__getattr__` +If an :exc:`AttributeError` is raised and the object has a :meth:`!__getattr__` method, that method is called as a fallback. .. _subscriptions: From b8f4457c53a6d94460071ccb876fae57679c608e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 25 Nov 2023 00:25:34 -0600 Subject: [PATCH 6/6] Update Doc/reference/expressions.rst Co-authored-by: Alex Waygood --- Doc/reference/expressions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 535c5d2ced03c12..3f6d5bfafee9d14 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -829,7 +829,7 @@ reference may yield different objects. This production can be customized by overriding the :meth:`~object.__getattribute__` method or the :meth:`~object.__getattr__` -method. The :meth:`__getattribute__` method is called first and either +method. The :meth:`!__getattribute__` method is called first and either returns a value or raises :exc:`AttributeError` if the attribute is not available.