[Pyrex] Inheritance for extension types

Konrad Hinsen hinsen at cnrs-orleans.fr
Thu Feb 12 15:07:22 CET 2004


On Thursday 12 February 2004 13:34, q q wrote:

> This does not compile and i get a traceback from
> Python.

Your example compiles fine for me, and I can import the resulting module. I 
can also create instances of type A. Creating an instance of type B causes a 
crash though.

I guess the reason is that you are calling a superclass method within __new__. 
When the method __new__ is called, the object is not yet in a consistent 
internal state, which means that some operations are not allowed. I don't 
know the details because I don't need to - unless you have a good reason to 
implement __new__, just implement (and override) __init__. In fact, it you 
replace __new__ by __init__ in your code, you should get everything working 
as expected.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------





More information about the Pyrex mailing list