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

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


[Thomas]

Well, there is the CALLATTR 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 CALLATTR 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/)