Re: Python 2.6 Deprecation Warnings with __new__ — Can someone expla in why?
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6 Deprecation Warnings with __new__ — Can someone expla in why?
Consider this: def blackhole(*args, **kwds): pass The fact that it accept args that it ignores could be considered misleading or even a bug. Now modify it to do something useful, like return a new, naked, immutable object that is the same for every call except for identity, and which still totally ignores the args as irrelavant. Call it object.__new__. It is just as misleading, if not more so. In 3.x, the mistake has been fixed. object(1) Traceback (most recent call last): File pyshell#9, line 1, in module object(1) TypeError: object.__new__() takes no parameters Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list