[Cython] Type casts

Robert Bradshaw robertwb at math.washington.edu
Tue Feb 5 08:08:39 CET 2008


Done.

On Feb 1, 2008, at 10:12 PM, Stefan Behnel wrote:

> Hi Robert,
>
> Robert Bradshaw wrote:
>> Currently, in Cython, when x is a python object, <int>x gives the
>> address of x. This is counter-intuitive and rarely useful. (When it
>> is, one can always do <size_t><void *>x).
>>
>> I would propose making <type>x do a conversion (the same as cdef type
>> y = x would) whenever type is a non-object type and x isn't, or vica-
>> versa. Between C types it already behaves this way, and between
>> Python objects it already has special meaning.
>
> +1
>
> The first thing I tried when I hit the bool expr problem, was changing
>
>     if n is None or n == 0:
>
> into
>
>     if n is None or <bint>(n == 0):
>
> which did not quite give the expected result.
>
>
>> I would also propose something like
>>
>> <ExtensionType?>x to be a cast into type ExtensionType *with* type
>> checking.
>
> I think that's also a good idea.
>
> BTW, we shouldn't forget to document syntax extensions in the wiki,  
> so that
> people (including Greg) know what works.
>
> Stefan



More information about the Cython-dev mailing list