__new__

Steven Bethard steven.bethard at gmail.com
Tue Nov 8 14:57:37 EST 2005


James Stroud wrote:
> Hello All,
> 
> I'm running 2.3.4
> 
> I was reading the documentation for classes & types
>        http://www.python.org/2.2.3/descrintro.html
> And stumbled on this paragraph:
> 
> """
> __new__ must return an object. There's nothing that requires that it return a 
> new object that is an instance of its class argument, although that is the 
> convention. If you return an existing object, the constructor call will still 
> call its __init__ method. If you return an object of a different class, its 
> __init__ method will be called.
> """

Any reason why you're looking at 2.2 documentation when you're running 2.3?

Anyway, the current docs corrected this mistake[1]

"""
If __new__() returns an instance of cls, then the new instance's 
__init__() method will be invoked like "__init__(self[, ...])", where 
self is the new instance and the remaining arguments are the same as 
were passed to __new__().

If __new__() does not return an instance of cls, then the new instance's 
__init__() method will not be invoked.
"""

[1]http://docs.python.org/ref/customization.html

STeVe



More information about the Python-list mailing list