[Pyrex] [Pyrex, Cython]Subclass basic exceptions inside Pyrex
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Oct 2 02:31:19 CEST 2008
Daniele Pianu wrote:
> I've some problems subclassing the basic extension type. The idea is
> to create my own exception hierarchy inside the Pyrex code, extending
> basic Python exception objects. This is my code
>
> cdef extern class __builtin__.Exception [object PyExc_Exception]:
> pass
> cdef class MyPyrexException( Exception ):
> pass
There are various things going on here:
1) The object struct for the builtin exception type isn't PyExc_Exception,
it's PyBaseExceptionObject.
2) It's declared using a typedef.
3) It's declared in pyerrors.h, which doesn't get included from Python.h.
Taking all that into account, you need to do something
like this:
cdef extern from "pyerrors.h":
ctypedef class __builtin__.Exception [object PyBaseExceptionObject]:
pass
--
Greg
More information about the Pyrex
mailing list