[Python-Dev] Instance variable access and descriptors
Phillip J. Eby
pje at telecommunity.com
Sun Jun 10 01:30:41 CEST 2007
At 12:23 AM 6/10/2007 +0300, Eyal Lotem wrote:
>A. It will break code that uses instance.__dict__['var'] directly,
>when 'var' exists as a property with a __set__ in the class. I believe
>this is not significant.
>B. It will simplify getattr's semantics. Python should _always_ give
>precedence to instance attributes over class ones, rather than have
>very weird special-cases (such as a property with a __set__).
Actually, these are features that are both used and desirable; I've
been using them both since Python 2.2 (i.e., for many years
now). I'm -1 on removing these features from any version of Python, even 3.0.
>C. It will greatly speed up instance variable access, especially when
>the class has a large mro.
...at the cost of slowing down access to properties and __slots__, by
adding an *extra* dictionary lookup there.
Note, by the way, that if you want to change attribute lookup
semantics, you can always override __getattribute__ and make it work
whatever way you like, without forcing everybody else to change *their* code.
More information about the Python-Dev