[Cython] Prototype for parametrized types

Stefan Behnel stefan_ml at behnel.de
Tue Mar 11 09:58:18 CET 2008


Hi,

Robert Bradshaw wrote:
> On Mar 11, 2008, at 1:36 AM, Stefan Behnel wrote:
>>> On Mar 10, 2008, at 4:48 PM, Dag Sverre Seljebotn wrote:
>>>> @cython(args=("x", cython.types.int), ret=cython.types.int, except=-1)
>>>> def foo(x):
>>
>> One drawback of the decorator notation: I don't think you can express
>> pointers and external C types (structs etc.) in any sensible way,
> 
> Yeah, it could get ugly:
> cython.types.pointer(cython.types.pointer(cython.types.int))." At this
> point string processing might not be bad, i.e. cython.type("int**") or
> even "int**" if it's clear from context that we're specifying a type. (I
> do want to avoid putting to much semantic information into "black box"
> strings though).

We could provide standard pointer and array types (p_int, int_array), but
there are always limits. Something like cython.parse_type("int**") would work
nicely, though, and would obviously reuse the parser, so you'd still get
compile time syntax checking. And since the decorator annotations would run
before the type analysis, undeclared types can be caught as well.

Stefan


More information about the Cython-dev mailing list