[Cython] Fused Types

mark florisson markflorisson88 at gmail.com
Thu Apr 28 22:11:29 CEST 2011

On 28 April 2011 22:10, mark florisson <markflorisson88 at gmail.com> wrote:
> On 28 April 2011 21:58, Stefan Behnel <stefan_ml at behnel.de> wrote:
>> 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
>> _______________________________________________
>> cython-devel mailing list
>> cython-devel at python.org
>> http://mail.python.org/mailman/listinfo/cython-devel
> When you call type you kind of expect it to call the Python builtin
> type(), which means it will coerce your C type to a Python object, on
> which it will call type(). So if you change those semantics suddenly
> for C types, I think we'd break people's code.

Also, you'd want this to work for Python types too, for instance for
two differently typed extension type attributes

More information about the cython-devel mailing list