[Numpy-discussion] proper use of __new__

Matthew Brett matthew.brett@gmail....
Tue Jul 21 12:37:02 CDT 2009


Hi,

> The words of caution were intended to remind that setting the value
> of  new array attributes in __new__ only could lead to problems, as
> it's possible to transform a ndarray into a subclass with a view (that
> is, calling __array_finalize__ without calling __new__). In the Simple
> Example of the doc, if .info cannot be None but must have a default
> DEFAULT, you should have a
>  >>> self.info = getattr(obj, 'info', DEFAULT)
> in your __array_finalize__

I'm the person who removed the reference to thread-safeness in the
numpy version of the subclassing docs.   I remember at the time going
through all the email discussions that led up to the thread-safeness
question, and concluding (in discussion with Travis O and others) that
there was not an increased threading problem with __new__  but
understanding why it came up in the first place.  I can't now
reconstruct that understanding, I could have a go if y'all want some
summary...

Best,

Matthew


More information about the NumPy-Discussion mailing list