[Pyrex] Subclassing numpy.ndarray with Pyrex

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Feb 6 00:56:12 UTC 2007


Pierre GM wrote:
> Moreover, the __array_finalize__ seems to be called 
> before the __new__ of my subclass, which is a tad surprising

Pyrex generates a call to the base class tp_new method
before calling your __new__ method, so if the base class
calls __array_finalize__ during its initialisation, then
it will get called before your __new__ method. In that
situation, it's not safe to refer to Python attributes of
your class, because they won't have been initialised to
None yet.

I don't know enough about Numpy and its use of
__array_finalize__ to suggest a solution, other than that
you try to find some way of doing all your initialisation
in the __new__ method. What is the 'obj' parameter and
where does it come from?

--
Greg



More information about the Pyrex mailing list