[Pyrex] extending a builtin type
Robin Becker
robin at reportlab.com
Thu Nov 22 11:15:27 CET 2007
Greg Ewing wrote:
> Robin Becker wrote:
>> I'm a bit unclear how to carry out initialization for this case.
>
> Pyrex will take care of calling the base class __new__
> for you. If you want to initialise C attributes of your
> own, write a __cinit__ method to do that.
>
> Optionally you can write an __init__ that passes whatever
> arguments you want to list.__init__, which is what will
> determine the initial contents of the list.
>
I'm still not certain about the taxonomy of methods and attributes. My
experiments show that __cinit__ is called before __init__ and that self is
already at least partially initialized ie
cdef class ObjectList(list):
cdef public int debug
def __cinit__(self,*args):
print '__cinit__',self, args
def __init__(self,*args):
list.__init__(self,*args)
print '__init__',self, args
self.debug = 0
ObjectList([1,2,3]) produces
__cinit__ [] ([1, 2, 3],)
__init__ [1, 2, 3] ([1, 2, 3],)
Is there a reason not to do the list.__init__ initialisation from args in __cinit__?
--
Robin Becker
More information about the Pyrex
mailing list