Greg Ewing wrote:
Variables declared as referring to extension types also accept the value None, because you need some way of representing a null value.
I see - that makes sense.
you can override this by declaring the argument as "not None", e.g. def none_test(np.ndarray[np.uint8_t, ndim=1, mode="c"] a not None): You will then get an exception if you try to pass None to this function.
That works, thanks.
(In Pyrex I'm thinking about changing this so that the default is *not* to accept None for an argument value, because this seems to trip up a lot of people.)
I agree -- I think that makes more sense as the default -- if a function accepts None, there will almost always have to be special case case to handle it anyway.
Dag Sverre Seljebotn wrote:
Note also that in Cython there is a "nonecheck" compiler directive. If you write #cython: nonecheck=True at the top of your file, an exception will be raised instead.
Not for me: this seems to have no effect. Nor does using it as a decorator: @cython.nonecheck(True) Cython 0.11.2 unrelated note:The cython module doesn't seem to have a "__version__" attribute. Perhaps it should, this has become pretty much a standard, and it's the first place I tried to look to see what version I was running.
Thanks, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [email protected]
import cython
import numpy as np
cimport numpy as np
@cython.nonecheck(True)
def none_test(np.ndarray[np.uint8_t, ndim=1, mode="c"] a ):
return a
test_cython_none.py
Description: application/python
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
