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

John Roth newsgroups at jhrothjr.com
Fri Feb 20 07:48:45 EST 2004


"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.

John Roth


> -- 
> Aahz (aahz at pythoncraft.com)           <*>
http://www.pythoncraft.com/
>
> "Argue for your limitations, and sure enough they're yours."  --Richard
Bach





More information about the Python-list mailing list