[Cython] Type casts
Stefan Behnel
stefan_ml at behnel.de
Sat Feb 2 07:12:07 CET 2008
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