Subclassing in C

Iker Arizmendi iker at research.att.com
Wed Sep 15 18:10:16 CEST 2004


Michael Hudson wrote:
> OK, some questions.
> 
> 1) You must be assuming 2.2 or later, right?  tp_base doesn't make
>    sense before then.

Yup, 2.2 or later (although I'm currently using 2.3).

> 2) Is this a third party base type?

Not really, it's written by another fellow here. But
I have access to the source and am free to make small
changes.

> 3) If 2) is the third party assuming 2.2 or later?

I think it was written before 2.2, but I've made some
changes that I think make it 2.2 compliant (eg, I added
the Py_TPFLAGS_BASETYPE flag, prepared the type with
PyType_Ready, and changed it to use tp_getattro instead
of tp_getattr.

> If 2) but not 3), you might be in for some hacking (as you later came
> up with).  You can't really subclass (cleanly) a type that's totally
> unprepared for it.

So I guess I have (!2 && !3), but I think I've managed
to change that to (!2 && 3). So assuming I have two types,
both written in C, what's the clean way to do the
subclassing? In particular, it would be nice if the C API
did the search of my bases for me.

> 
> Py_FindMethod() is SO 2001 :-)

Just got started with Python and put on the first thing
I found. Didn't realize they were bell bottoms :)

Is there a newer method?


Regards,
Iker



More information about the Python-list mailing list