Why property works only for objects?

Michal Kwiatkowski ruby at no.spam
Sat Mar 11 18:11:22 EST 2006


Alex Martelli napisał(a):
>> It still bugs me. What's the actual procedure when doing attribute
>> assignment? I understand it like this:
>>
>> obj.attr = value
>>  * if instance class has __setattr__, call it
>>    * else: if class has an attribute with name "attr" check if it's a
>>      descriptor; when it's overriding descriptor, call its __set__
>>      method, otherwise raise AttributeError
>>      * else: bind "attr" as object attribute
> 
> Yes, this is correct.

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

> Opening a bug report on the Python bugtracker would maximize the
> likelihood that something gets done about this bug.

Bug submitted:

http://sourceforge.net/tracker/index.php?func=detail&aid=1448042&group_id=5470&atid=105470

mk
-- 
 . o .       >>  http://joker.linuxstuff.pl  <<
 . . o   It's easier to get forgiveness for being wrong
 o o o   than forgiveness for being right.



More information about the Python-list mailing list