Why property works only for objects?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sat Mar 11 18:56:05 CET 2006


Michal Kwiatkowski a écrit :
> Bruno Desthuilliers napisał(a):
> 
>>>Let me understand it clearly. If I change __class__ of an object,
>>>existing attributes (so methods as well) of an object are still
>>>accessible the same way and don't change its values. Only resolution of
>>>attributes/methods not found in object is changed, as it uses new
>>>version of __class__ to lookup names. Is this right?
>>
>>Attributes, yes. Not methods. Methods are looked up in the class.
> 
> 
> My experience shows exactly the opposite. Any attribute/method you try
> to access is first looked up in object dictionary, then inside class
> definition.

Yes, that's what I said.

You wrote:
"""
existing attributes (so methods as well) of an object are still
accessible the same way and don't change its values
"""

Attributes (I mean instance attributes) living in the object's dict, 
they aren't impacted by the runtime class change. Methods being in the 
most common case (I'd say > 99.9 %) defined *in the class*, if you 
change the class of an object, this is very likely to impact resolution 
of methods lookup.

Now I agree that the statement "methods are looked up in the class" is 
wrong. Methods are of course first looked up in the object, then in the 
class. But the case of a method living in the object's dict is not that 
common...



More information about the Python-list mailing list