[Pyrex] [Cython] Proposed change to behaviour of "not None"

Stefan Behnel stefan_ml at behnel.de
Tue Aug 26 22:18:44 CEST 2008


Hi,

Robert Bradshaw wrote:
> To me the idea that exactly one of
> 
> def foo(ExtType x):
>      ...
> 
> cdef foo(ExtType x):
>      ...
> 
> can accept None, and the other throws an error, is counterintuitive. I do 
> see a difference (def functions are exposed to the "outside world") but I 
> think people are just as likely to shoot themselves in the foot with the 
> second option as well.

FWIW, I'm with Robert here. Having automatic argument checking in one special
(and very visible) place will let users forget to do the checking themselves
in the other places, which might even increase the chance of writing broken code.

I'm also not sure I find it counter-intuitive that a declared extension type
parameter cannot contain None. All Python references can be None, so why not
that one? I think there are about as many reasons why people would expect one
behaviour as for expecting the other.


> And people will still have to be careful with
> 
> cdef ExtType x = foo()
> x.cdef_attribute

It would be nice if this could be solved by better flow analysis, but I doubt
that it can be achieved with reasonable effort.

Stefan



More information about the Pyrex mailing list