Re: Python 2.6 Deprecation Warnings with __new__ — Can someone explain why?

Terry Reedy tjreedy at udel.edu
Mon Oct 26 17:14:00 CET 2009


Carl Banks wrote:

>> So what is the point of using __new__?

.__new__ creates new objects. It also inializes 'immutable' objects.

> It's mostly for types written in C, or for subclassing types written
> in C.

Specifically, for subclassing immutable classes where one wants 
initialization behavior different from that provided by the superclass.

 > Advanced programmers can take advantage of it to do some
> interesting things, but most of the time __init__ suffices.

Initialization of mutables should be done in .__init__. Most 
user-defined classes define mutables.

Terry Jan Reedy





More information about the Python-list mailing list