__new__ does not call __init__ as described in descrintro.html (WAS:Can __new__ prevent __init__ fro

S

Steven Bethard

Felix said:
> [snip]
>
> I'm just seeing that the web page says:
>
> | 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.
>
> However, the latter doesn't seem to be true, or am I missing
> something?
> > ... def __init__(self):
> ... print 'Init of A.'
> ...
> > Init of A.
> > ... def __new__(self):
> ... return instance
> ... def __init__(self):
> ... print 'Init of B.'
> ...
> > Init of B.
> <__main__.B object at 0x406243ec>
>
> So there seems to be some type-checking in type.__call__.

Yeah, I saw the same thing in playing around with this. Don't know what
to make of it. I wonder if we should file a documentation bug? I can't
find __new__ explained anywhere in the Language Reference. Can
documentation bugs be filed for descrintro.html?

STeVe
 
A

Aahz

Yeah, I saw the same thing in playing around with this. Don't know
what to make of it. I wonder if we should file a documentation bug? I
can't find __new__ explained anywhere in the Language Reference. Can
documentation bugs be filed for descrintro.html?

Absolutely! And they're especially welcome if they contain suggested
replacement text.
--
Aahz ([email protected]) <*> http://www.pythoncraft.com/

"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code --
not in reams of trivial code that bores the reader to death." --GvR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top