[Python-Dev] Fwd: Instance variable access and descriptors
Phillip J. Eby
pje at telecommunity.com
Sun Jun 10 20:28:23 CEST 2007
At 11:27 AM 6/10/2007 +0100, Gustavo Carneiro wrote:
> I have to agree with you. If removing support for
> self.__dict__['propertyname'] (where propertyname is also the name
> of a descriptor) is the price to pay for significant speedup, so be
> it. People doing that are asking for trouble anyway!
How so? This order of lookup is explicitly defined by the precedence
rules of PEP 252:
"""When a dynamic attribute (one defined in a regular object's
__dict__) has the same name as a static attribute (one defined
by a meta-object in the inheritance graph rooted at the regular
object's __class__), the static attribute has precedence if it
is a descriptor that defines a __set__ method (see below);
otherwise (if there is no __set__ method) the dynamic attribute
has precedence. In other words, for data attributes (those
with a __set__ method), the static definition overrides the
dynamic definition, but for other attributes, dynamic overrides
static."""
I fail to see how relying on explicitly-documented language behavior
is "asking for trouble".
More information about the Python-Dev
mailing list