[Cython] Safer exception handling

Stefan Behnel stefan_ml at behnel.de
Mon Sep 17 16:07:23 EDT 2018


Robert Bradshaw schrieb am 17.09.2018 um 15:44:
> One of the pain points in Cython is that one must explicitly annotate
> non-object returning functions with except clauses. Would it be worth
> trying to change the default here, making exception-suppressing opt-in
> rather than opt-out?
> 
> There are a couple of open questions, e.g.
>   * What would the syntax be?
>   * What about extern functions?
>   * What would the performance impact be? Could it be mitigated?

Probably a good idea, and worth a 3.0 ticket.

Note that the default for return type annotations is to automatically
propagate exceptions, in order to keep the drop from Python semantics gentle.

   @cython.cfunc
   def func() -> cython.int:
       ...

is read as "except? -1", unless declared otherwise.

Stefan


More information about the cython-devel mailing list