[Python-Dev] CALL_ATTR patch (was: 2.3b1 release)

Guido van Rossum guido@python.org
Thu, 17 Apr 2003 11:53:01 -0400

> Well, there is the CALL_ATTR patch (http://www.python.org/sf/709744)
> that Brett and I worked on at the PyCon sprints. It's finished
> (barring tests) for classic classes, and writing tests is not very
> inspiring because all functionality is already tested in the
> standard test suite. However, it doesn't do anything with newstyle
> classes at all, yet.

And I want the new-style classes version!

> I've had suprisingly little time since PyCon (it's amazing how not
> being at the office for two weeks makes people shove work your way
> -- I guess they realized I couldn't object :)

Even without so much that problem here, I was buried in email for a
week after returning from Python UK. :-)

> but I'm in the process of grokking newstyle classes. So far, I've
> been alternating from 'Wow! to 'Au!', and I'll send another email
> after this one for clarification of a few issues :) Anyway, if
> anyone has straightforward ideas about how CALL_ATTR should deal
> with newstyle classes (if at all), please inform me (preferably via
> SF) or just grab the patch and run with it. I'm still confused about
> descrgets and where they come from.

Yes, please.  Here's a quick explanation of descriptors:

A descriptor is something that lives in a class' __dict__, and
primarily affects instance attribute lookup.  A descriptor has a
__get__ method (in C this is the tp_descrget function in its type
object) and the instance attribute lookup calls this to "bind" the
descriptor to a specific instance.  This is what turns a function into
a bound method object in Python 2.2.  In earlier versions, functions
were special-cased by the instance getattr code; the special case has
been subsumed by looking for a __get__ method.  Yes, this means that a
plain Python function object is a descriptor!  Because the instance
getattr code returns whatever __get__ returns as the result of the
attribute lookup, this is also how properties work: they have a
__get__ method that calls the property-get" function.

A descriptor's __get__ method is also called for class attribute
lookup (with the instance argument set to NULL or None).  And a
descsriptor's __set__ method is called for instance attribute
assignment; but not for class attribute assignment.

Hope this helps!

--Guido van Rossum (home page: http://www.python.org/~guido/)