The Don Beaudry/Jim Fulton hack

Gordon McMillan gmcm at hypernet.com
Thu Dec 30 22:13:49 EST 1999


Dave Abrahams wrote:

> In article <1265560092-4227862 at hypernet.com> , "Gordon McMillan"
> <gmcm at hypernet.com> wrote:
> 
> > Dave Abrahams wrote:
> >>
> >> I've recently been crawling through the source code (trying to
> >> understand what all those fields in PyTypeObject really do),
> >> and stumbled across an explanation for what I had read about
> >> being able to subclass a type extension in Python: there's
> >> special code to make this possible!
> >
> > Not really. That special code allows you to take over the
> > building of a new instance from Python. Subclassing a type
> > takes a whole lot of C code.
> 
> Yes, really.
> Even with a whole lot of 'C' code, you couldn't subclass a type
> extension without that bit of special code. That bit of special
> code is what makes it possible.

Misunderstanding. I thought you meant "in Python". There 
was an earlier hook that allowed you to do this stuff in C. The 
current hook works for both, of course, but AFAIK, only 2 
people have used the hook in C, and only one implementation 
works with Python 1.5. It's most popular use is for 
"acquisition", which is not only possible in pure Python, it's 
possible to do it with proxies instead of metaclasses.

> > IOW, this was an easy way to test
> > out an experimental feature, not an axiom of the object model.
> 
> Yes; I was intending to explore it experimentally before I
> started writing C++ code.

I meant the hook was (and is) experimental. Python 2 is likely 
to have a completely different object model in which types and 
classes are merged, and metaclasses have play a part in the 
object model. To date, the only known use for this stuff is to 
do hidden getattr and setattr tricks. 
 



- Gordon




More information about the Python-list mailing list