I'm looking for a complete description of Python attribute lookup. I know there have been similar questions and there is this very nice introduction to the descriptor protocol. But it does not cover the entire lookup for example it does not elaborate on special methods.
Ideally, there would be a flowchart starting at x.y
and then running through all possibilites including
- is it lookup or assignment?
- is
x
a class or an object (or for example a function if that makes a difference)? - is
x
a builtin if that's relevant? - does
x
have a__slots__
attribute? - does
x
have a__getattr__
,__setattr__
or__getattribute__
method? - is
y
, the string a special attribute name - once
y
is resolved, does it have a__get__
attribute?
etc., etc., you get the idea.
I realise this is a lot of work, so if there are any promising submissions within 5 days from now I'm willing to offer a 250 rep bounty.
Reference version should be Python3.6 and there should be an effort made to demonstrate completeness as far as possible.
I'm sure such a flowchart would be tremendously useful for me and many others.