[Cython] Fused Types

Stefan Behnel stefan_ml at behnel.de
Thu Apr 28 21:58:14 CEST 2011


mark florisson, 28.04.2011 21:48:
> I'm currently wondering about the proposed
> cython.typeof(). I believe it currently returns a string with the type
> name, and not the type itself. So I think it would be inconsistent to
> suddenly start allowing comparison with 'is' and 'isinstance' and
> such.
>
> I'm also wondering if it would be useful to allow actual type
> retrieval, which could be used in declarations and casts. For instance
> consider fusing two structs with the same attribute name but different
> attribute types. Perhaps in your code you want to introduce a variable
> compatible with such a type, e.g. consider this:
>
> ctypdef struct A:
>      int attrib
>
> ctypedef struct B:
>      char *attrib
>
> ctypedef cython.fused_type(A, B) struct_t
>
> cdef func(struct_t mystruct, int i):
>      cdef cython.gettype(mystruct.attrib) var = mystruct.attrib + i

What's wrong with type() ?

Stefan


More information about the cython-devel mailing list