[Pyrex] extending a builtin type

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Nov 23 00:03:34 CET 2007


Robin Becker wrote:
> 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

What happens is this: Pyrex generates a __new__ method for
you that

   1) Calls the base class's __new__ method to create the object

   2) Initialises any Python-valued C attributes declared at that
      level of the inheritance hierarchy to None

   3) Calls your __cinit__ method

> Is there a reason not to do the list.__init__ initialisation from args in __cinit__?

There are two separate phases to creating a Python object, each
with its own chain of methods -- the __new__ phase. and the __init__
phase. The __cinit__ method is part of the __new__ phase. The
__init__ phase is initiated automatically after the __new__ phase,
so if you called __init__ from the __new__ phase, it would end
up getting called twice.

--
Greg








More information about the Pyrex mailing list