[Cython] subclassing builtin

Stefan Behnel stefan_ml at behnel.de
Fri Apr 17 16:39:04 CEST 2009


Lisandro Dalcin wrote:
> On Fri, Apr 17, 2009 at 10:51 AM, Riccardo Murri wrote:
>> I cannot get the documented method to work::
>>
>>  $ cat t.pyx
>>  cdef extern from "tupleobject.h":
>>      ctypedef class __builtin__.tuple [object PyTupleObject]:
>>          pass
>>
>>  cdef class MyTuple(tuple):
>>      pass
>>
>
> Tuples are a different beast... They are PyObject_VAR_HEAD structures

Yep, that's a missing feature. It's not trivial to implement as this
requires a special case in the way Cython deals with subtypes, likely with
a major code impact.

http://trac.cython.org/cython_trac/ticket/152

It's usually best to use a normal Python class to subtype str (Py2.x) and
tuple, instead of a cdef class.

Stefan



More information about the Cython-dev mailing list