Ticket #513 (new enhancement)

Opened 5 months ago

Last modified 5 months ago

Infer return types of cdef functions

Reported by: scoder Owned by: somebody
Priority: major Milestone: wishlist
Component: Type Analysis Keywords:
Cc:

Description

For example, it would be nice if Cython could figure out that a function like this always returns a tuple:

cdef test(x):
    return x*2, x**2

# this shouldn't generate all the generic unpacking code:
a,b = test(5)

Change History

Changed 5 months ago by dagss

Perhaps we should first make a "typed tuple type" in the language which can be used explicitly, and then talk about inference afterwards. E.g.

cdef (int, float) test((int, float) x):
    return x[0]*2, x[1]*2

Not sure that's the most readable syntax but it should serve as an example. It would probably map directly to a C struct for simplicity.

Changed 5 months ago by scoder

I think that's orthogonal enough to become a separate feature request.

Note: See TracTickets for help on using tickets.