[Pyrex] Parameter type check

David M. Cooke cookedm at physics.mcmaster.ca
Fri Apr 15 19:07:46 CEST 2005


Joachim Saul <saul at gfz-potsdam.de> writes:

> Hello,
>
> in my Pyrex codes I heavily make use of "strong typing" like
>
>     cdef class IIR_Filter:
>
>         def apply(self, ArrayType input):
>             ...
>
> where ArrayType is a Numeric array type. In earlier versions of
> Pyrex, the same code above used to raise a TypeError whenever the
> input was not a Numeric array. However, with 0.9.3 this is not the
> case any more. If input is for instance None, no exception is
> raised and since there is no further type check, the program
> crashes.

I'm guessing that this occurs *only* for None, as that is an allowed
value. Have a look at the Extension Types page in Pyrex's language
reference:

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/extension_types.html#NotNone

What you want is to add 'not None':

cdef class IIR_Filter:
    def apply(self, ArrayType input not None):
        ...

Reason for this? I don't know, only Greg Ewing knows for sure.
Although it is useful in the same way that passing a NULL pointer in C
is useful: sometimes that makes sense.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca



More information about the Pyrex mailing list