[Pyrex] Inheritance for extension types

Greg Ewing greg at cosc.canterbury.ac.nz
Fri Feb 13 01:09:57 CET 2004


alainpoint at yahoo.fr:

> cdef class B(A):
>    def __new__(self,int length, int width):
>        A.__new__(self,length)
>        self.width=width
> 
> This does not compile and i get a traceback from
> Python.

If you're getting a traceback from the Pyrex compiler, then
there's a bug. I'll look into it.

> The documentation does not give any info about how
> transmit parameters to the parent class

You can't do that with __new__ at the moment, because Pyrex
calls the base class __new__ automatically before calling
the subclass __new__, and you don't get a chance to influence
the parameters.

You should be able do this with __init__ instead of __new__, though:

cdef class A:
   def __init__(self,int length):
      self.length=length

cdef class B(A):
   def __init__(self,int length, int width):
       A.__init__(self,length)
       self.width=width

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list