subclassing extension type and assignment to __class__

gregory lielens gregory.lielens at
Sun Nov 28 00:50:28 CET 2004

Thanks for your answer, it means I am not the only one having this kind 
of problem...
> I have just run into the same thing with the builtin list type. The trick
> was not to declare my subclass directly from list, but rather a subclass
> of list. So try this:
> class PClassBase(_PClass):
>     pass
> class PClass(PClassBase):
>     ...
> class PClass2(PClassBase):
>     ...
I think here you mean PClass2(PClassBase2), with a 
PClassBase2(_PClass2): In my example the 2 class do not inherit fro the 
same base class...
> Why? I cannot say other than I have noted that Python new-style classes
> and extension types are not quite the same thing. That is, a new-style
> class is a particular kind of extension type.

I see how it can help me making PClassBase a PClass (or any type derived 
from PClassBase), but what I fail to see is how this will allow me to 
change a _PClass into one of it's derived types: this is necessary for 
updating methods of _PClass2 that return object of type _PClass (and on 
this I do not have much control, both _PClass and _PClass2 and all of 
their methods are implemented in C++). To updates theses methods for the 
pure python derived class PClass2, I have to make them return the python 
class PClass instead of the original _PClass, which means I still have 
to transform a _PClass object into its derived type PClassBase or 
PClass, and at this time things go pear-shaped :-(....or is there 
something I miss?


More information about the Python-list mailing list