2

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.

Community
  • 1
  • 1
Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
  • Dear mods. Any chance of a bit of clarification? I fail to see how there could be "too many possible answers"; as for the length do you know for a fact that a flowchart with a handful of references would not fit "a few paragraphs"? – Paul Panzer Feb 15 '17 at 12:16
  • This blog is a good start: https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/#object-attribute-lookup – Angus Hollands Jul 29 '22 at 11:45

0 Answers0