]> granicus.if.org Git - python/commitdiff
[3.7] bpo-8722: Document __getattr__ behavior with AttributeError in property (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 5 Feb 2018 03:16:49 +0000 (19:16 -0800)
committerNick Coghlan <ncoghlan@gmail.com>
Mon, 5 Feb 2018 03:16:49 +0000 (13:16 +1000)
When `__getattr__` is implemented, attribute lookup will always fall back to that,
even if the initial failure comes from `__getattribute__` or a descriptor's `__get__`
method (including property methods).
(cherry picked from commit d1f318105b8781b01f3507d5cb0fd841b977d5f2)

Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
Doc/reference/datamodel.rst
Misc/NEWS.d/next/Documentation/2018-02-03-06-11-37.bpo-8722.MPyVyj.rst [new file with mode: 0644]

index 25b95c115438b3b9e431eb261c7c0b7ef7ccefa8..8420fb60bff37a67d3a4b637b0a79b5358fcabb6 100644 (file)
@@ -1463,10 +1463,12 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
 
 .. method:: object.__getattr__(self, name)
 
-   Called when an attribute lookup has not found the attribute in the usual places
-   (i.e. it is not an instance attribute nor is it found in the class tree for
-   ``self``).  ``name`` is the attribute name. This method should return the
-   (computed) attribute value or raise an :exc:`AttributeError` exception.
+   Called when the default attribute access fails with an :exc:`AttributeError`
+   (either :meth:`__getattribute__` raises an :exc:`AttributeError` because
+   *name* is not an instance attribute or an attribute in the class tree
+   for ``self``; or :meth:`__get__` of a *name* property raises
+   :exc:`AttributeError`).  This method should either return the (computed)
+   attribute value or raise an :exc:`AttributeError` exception.
 
    Note that if the attribute is found through the normal mechanism,
    :meth:`__getattr__` is not called.  (This is an intentional asymmetry between
diff --git a/Misc/NEWS.d/next/Documentation/2018-02-03-06-11-37.bpo-8722.MPyVyj.rst b/Misc/NEWS.d/next/Documentation/2018-02-03-06-11-37.bpo-8722.MPyVyj.rst
new file mode 100644 (file)
index 0000000..36e6ff7
--- /dev/null
@@ -0,0 +1,2 @@
+Document :meth:`__getattr__` behavior when property :meth:`get` method
+raises :exc:`AttributeError`.