[New-bugs-announce] [issue39614] Documentation of attribute reference is unclear
report at bugs.python.org
Tue Feb 11 18:17:29 EST 2020
New submission from Dirk Herrmann <dirk.herrmann-privat at gmx.de>:
Trying to understand attribute reference in Python, I was lost:
* In the "Python Language Reference" (I will refer to this as PLR, sorry if that is uncommon, did not find an abbreviation in the glossary): Chapter 6.3.1 is about attribute reference. How the attribute reference actually works is not explained in detail, only with the sentence "This object is then asked to produce the attribute whose name is the identifier." which I find vague. Moreover, in PLR 6.3.1 it is said that it can be customized overriding "__getattr__()", but again, details are unclear. And, when following the link to "__getattr__()" it turns out that "__getattr__()" is not called for attribute access, but only in certain circumstances:
* PLR 3.3.1 section "object.__getattr__(self, name)" explains that this is only called when "default attribute access" fails. There is nowhere an explanation of "default attribute access", it is also not mentioned in the index. There is some explanation in parentheses what it means if "default attribute access" fails, but the actual procedure of the "default attribute access" is still not clear. A bit further down in this section it is also mentioned that if an attribute is found using the "normal mechanism" then "__getattr__()" is not called - again not explaining what the "normal mechanism" is. There is some reference to "__getattribute__()" here, saying that with "__getattribute__()" there would be "total control over attribute access", but this leads again to confusion:
* PLR 3.3.1 section "object.__getattribute__(self, name)" indicates that this "may still be bypassed" in certain circumstances, referring to PLR 3.3.10, special method lookup, which refers to the "conventional lookup process", to which this is an exception. The basis why this is an exception remains unclear - is it that certain method names are detected during attribute reference?
Summary: There is not (or I was too stupid to find) a concise description of how attribute reference works. There are several terms used to refer to certain aspects of it: "default attribute access", "normal mechanism [of attribute access]", "conventional lookup process", which may or may not refer to the same thing, which seems not to be documented anyway.
assignee: docs at python
nosy: Dirk Herrmann, docs at python
title: Documentation of attribute reference is unclear
versions: Python 3.8
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce