On 20/03/2022 05:47, Stefan Behnel wrote:
> Thought I'd try creating a struct and return that instead of a tuple.
>> Is there a more elegant way to do this?
> I'd use a tuple. And also declare the return type as tuple.
>
> Cython 3 has support for PEP 484 tuple item types, so you could declare them explicitly now and thus allow the caller to see exactly what it receives. Not sure if that leads to better code in the current state of the implementation, but it's certainly not wrong to be explicit and might help as we improve Cython.
>
> Stefan
>
The current status is:
* A tuple of C types is interpreted as a C tuple (i.e. internally
transformed to a struct in Cython).
* A tuple containing PyObjects is just returned as a normal tuple (since
Cython's C tuple optimization can't currently handle reference-counted
types)
That's currently on the master branch only and not on any alpha releases
(and I think the feature needs a little bit of fixing before it makes it
to an alpha release). So right now I don't think you can do much better
than "just return a tuple"