[Numpy-discussion] proper use of __new__

Darren Dale dsdale24 at gmail.com
Tue Jul 21 14:48:49 EDT 2009


On Tue, Jul 21, 2009 at 2:41 PM, Matthew Brett<matthew.brett at gmail.com> wrote:
> Hi,
>
>>> 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...
>>
>> Did this occur on the mailing list? Could you provide a link?
>
> Yes, here's the link:
>
> http://mail.scipy.org/pipermail/numpy-discussion/2007-February/025922.html
>
> I remember the argument now.  Sturla Molden was pointing out that iff
> you modify attributes at the class level in __new__, this is not
> thread safe - as happens with any global variable.  Usually of course
> you don't modify class attributes in the __new__ method, and in that
> case, expect no subclass threading problems.  The key post from Travis
> here:
>
> http://mail.scipy.org/pipermail/numpy-discussion/2007-February/025971.html

Thanks for the clarification. I updated the wiki to read:

The definition of default values for subclass attributes (as opposed
to instance attributes) in the {{{__new__}}} method is strongly
discouraged for several reasons: ...



More information about the NumPy-Discussion mailing list