[Cython] Minor bug: emitted junk line prevents compilation

Nikita Nemkin nikita at nemkin.ru
Sat Mar 16 22:30:58 CET 2013


On Sun, 17 Mar 2013 02:59:12 +0600, Stefan Behnel <stefan_ml at behnel.de>  
wrote:

>> In case you are interested in how to hit this line, declare in some  
>> .pxd:
>>
>>     cdef extern from "Python.h":
>>         ctypedef class __builtin__.BaseException [object  
>> PyBaseExceptionObject]:
>>             pass
>
> Why would you need to do that in your code?

It makes Cython treat BaseException as an extension type
(Exception is declared similarly) and allows for things like:

* Using "Exception" as a type for parameters, attributes, casts.
   All this with Cython-generated and optimized typeckecking.
* Creating Exception subclasses as cdef classes.

It's a hack, but a very useful one.

Best regards,
Nikita Nemkin


More information about the cython-devel mailing list