Definitive documentation on newstyle classes? (WAS: Pickling and inheritance are making me hurt)
Colin J. Williams
cjw at sympatico.ca
Wed Feb 9 09:25:02 EST 2005
Michele Simionato wrote:
>>It would be good to have a clear exposition of the pros and cons of
>>__new__ usage.
>
>
> It is there mostly because __init__ would not work on immutable types.
> OTOH, you probably do not want to use __new__ on mutable types
> (once I was caught by this trap, google for "overriding list.__new__"
> if you are interested).
>
> Michele Simionato
>
Thanks. The use of __new__ for immutable classes is described in:
http://www.python.org/2.2.3/descrintro.html
This distinction hadn't registered with me before.
The Martelli bible doesn't bring this out.
It seems to me that __new__ should probably be deprecated for mutable
classes.
Colin W.
More information about the Python-list
mailing list