Speed of attribute lookup (was Re: advice on programming style: is multiple inheritance bad?)

Aahz aahz at pythoncraft.com
Thu Mar 4 06:27:42 EST 2004


In article <103c0jdd33bhc3a at news.supernews.com>,
John Roth <newsgroups at jhrothjr.com> wrote:
>"Aahz" <aahz at pythoncraft.com> wrote in message
>news:c13mpp$9ic$1 at panix2.panix.com...
>> In article <101sphfjk91p42d at news.supernews.com>,
>> John Roth <newsgroups at jhrothjr.com> wrote:
>>>"Aahz" <aahz at pythoncraft.com> wrote in message
>>>news:bvkh00$38r$1 at panix1.panix.com...
>>>>
>>>> The problem with attribute lookup in new-style classes is that any
>>>> instance attribute could be a property.  So if Python finds an attribute
>>>> on the instance, it needs to traverse the MRO to check if there's a
>>>> property.  If there isn't one, that's an expensive waste.
>>>
>>>I thought about that when new style classes came out, and managed
>>>to convince myself that it couldn't happen, at least with data
>>>properties. Unless trying to set the *same* attribute from the setter
>>>invoked from the property actually works? That seems like a lot of work
>>>to make it function poorly.
>>
>> I'm not understanding your question.
>
>In order to determine if something is a property, you have to scan
>the MRO to find a descriptor. Correct? The only real problem case
>here is if the instance has an attribute that is named the same as the
>descriptor. My understanding is that this wasn't allowed, thus
>eliminating the necessity of scanning the MRO when the attribute
>was sitting right there in front of one.
>
>Now if the original discussion was about speeding up the descriptor
>search in the general case, then I misunderstood the issue.

Unfortunately, because one can assign to <object>.__dict__, there's no
way of preventing the existance of an object attribute.  (Was going to
write more, but don't have time.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Do not taunt happy fun for loops. Do not change lists you are looping over."
--Remco Gerlich, comp.lang.python



More information about the Python-list mailing list