[Cython] Issue with function annotations
Stefan Behnel
stefan_ml at behnel.de
Wed Sep 27 08:54:07 EDT 2017
Hi Lisandro,
Lisandro Dalcin schrieb am 27.09.2017 um 14:42:
> $ cython --version
> Cython version 0.27
>
> $ cat tmp.pyx
> def f() -> (list, list):
> return [], []
>
> $ cython tmp.pyx
>
> Error compiling Cython file:
> ------------------------------------------------------------
> ...
> def f() -> (list, list):
> ^
> ------------------------------------------------------------
>
> tmp.pyx:1:12: C struct/union member cannot be a Python object
>
> Error compiling Cython file:
> ------------------------------------------------------------
> ...
> def f() -> (list, list):
> ^
> ------------------------------------------------------------
>
> tmp.pyx:1:12: C struct/union member cannot be a Python object
Yes, I noticed that, too. It's a bit annoying. PEP 484 would spell this
using the "Tuple" type, i.e. "Tuple[list, list]", or even something like
"Tuple[List[Any], List[Any]]".
The problem in Cython is that the syntax is reserved for C tuples, which
are syntactically nicer structs. "(list, list)" is a struct with two member
lists, but since structs do not support reference counting, this is illegal
in Cython.
The best way to resolve this for now is probably to ignore C tuples in
function annotations entirely. At some point, Cython will have to learn to
understand complex PEP-484 types like Tuple[].
Stefan
More information about the cython-devel
mailing list