Author Dirk Herrmann
Recipients Dirk Herrmann, docs@python
Date 2020-02-11.23:17:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1581463049.18.0.764231801329.issue39614@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-02-11 23:17:29Dirk Herrmannsetrecipients: + Dirk Herrmann, docs@python
2020-02-11 23:17:29Dirk Herrmannsetmessageid: <1581463049.18.0.764231801329.issue39614@roundup.psfhosted.org>
2020-02-11 23:17:29Dirk Herrmannlinkissue39614 messages
2020-02-11 23:17:28Dirk Herrmanncreate