473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

__new__ does not call __init__ as described in descrintro.html (WAS:Can __new__ prevent __init__ from being called?)

Felix Wiemann wrote:
Steven Bethard wrote:
http://www.python.org/2.2.3/descrintro.html#__new__

[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?
class A(object): ... def __init__(self):
... print 'Init of A.'
...
instance = A() Init of A.
class B(object): ... def __new__(self):
... return instance
... def __init__(self):
... print 'Init of B.'
...
B() # <--------- A's __init__ is *not* called. <__main__.A object at 0x4062424c>
instance = object.__new__(B)
B() # <--------- B's __init__ is called

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
Jul 18 '05 #1
2 1478
In article <pv********************@comcast.com>,
Steven Bethard <st************@gmail.com> wrote:

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 (aa**@pythoncraft.com) <*> 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
Jul 18 '05 #2
Aahz wrote:
In article <pv********************@comcast.com>,
Steven Bethard <st************@gmail.com> wrote:
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.


Cool. I added a documentation bug:

http://sourceforge.net/tracker/?func...70&atid=105470

Steve
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dag Sunde | last post by:
Is there a way to detect if the reason an onUnload() handler was called originated from the user explicitly refreshed the page(s)? Ie. pressed "Ctrl-R", "F5" or klicked the refresh button in...
2
by: José Joye | last post by:
When I unload an appdomain I have created, I always get the following exeption: System.Threading.ThreadAbortException: Thread was being aborted. Before calling the Unload() method, I set to...
1
by: kosta | last post by:
hello! I have this code: public static DataSet DSet(String sql) { OleDbConnection con = new OleDbConnection(); con.ConnectionString = ConfigurationSettings.AppSettings; OleDbCommand cmd =...
1
by: GSK | last post by:
I am logging the following error when re-directing via Response.Redirect: "Thread was being aborted at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object...
0
by: Vishal | last post by:
Hello, I am reading several rss feeds and some of them takes sometime too long or sometimes they doesnt exist. However when I run the code I get a timeout with the following message: "Thread...
1
by: Josef K. | last post by:
I've started getting "Thread was being aborted" errors. This errormessage has me puzzled. I'm using the same very simple approach throughout the application, and it works elsewhere: -- my aspx...
0
by: Prasad Dannani | last post by:
I am facing a unique problem where i am reading an XMl stream(8000 records) using open XML into SQL server > The problem is that whenever i execute the stored procedure it starts inserting data...
5
by: Neil | last post by:
Hi, Long story short, we use "Server.Execute" to grab the output from an ASPX page ... Server.Execute("page.aspx", textWriter); We've noticed that intermittantly, we get a "Thread was being...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.