A
Alex Martelli
Michal Kwiatkowski said:Can you also check my reasoning for getting attributes?
value = obj.attr
* if instance class has __getattribute__, call it
* else: lookup "attr" in all parent classes using class __mro__;
if it's a descriptor call its __get__ method, return its value
otherwise (when descriptor doesn't have __get__, it's unreadable
and AttributeError is raised)
* else: check instance __dict__ for "attr", return it when found
* else: lookup __getattr__ in instance class and call it when found
* else: raise AttributeError
No, the value found in the instance (your second 'else' here) takes
precedence if the descriptor found in the first 'else' is
non-overriding.
The difference:
.... def __get__(*a): return 23
.... .... def __get__(*a): return 23
.... .... def __set__(*a): pass
....
Alex