[Pyrex] Adding tuple as builtin type

Claudio Freire klaussfreire at gmail.com
Wed Feb 11 15:37:14 CET 2009


Is there a reason why tuple hasn't been added as a builtin type, as list was?
In my code, there is heavy usage of tuples, and the generic code
generated by pyrex when working with them as generic "object"s leaves
something to be desired.

In particular, I rely heavily on returning tuples and then unpacking
them as a way to return more than one value:

cdef tuple threevalues():
   return (1,2,3)

def dosomething():
   cdef int a,b,c
   a,b,c = threevalues()
   return a+b+c

Without pyrex knowing of that return value's tuple status, the
generated code for unpacking is rather cumbersome, using iterators and
lots of checking. Knowing it's a tuple, only a few calls to
PyTuple_xxx API would be involved in unpacking those values. Since I
use pyrex code to implement compute-intensive parts of my application,
in performance-critical sections, the speed improvement would be
highly appreciated.

I considered using lists, but lists break things someplace else in the
app (I need it to be of an immutable type).

Sorry if it came up already, I searched through the archives a bit and
didn't see anything about the subject.



More information about the Pyrex mailing list