473,714 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

__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 1490
In article <pv************ ********@comcas t.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
documentatio n bugs be filed for descrintro.html ?


Absolutely! And they're especially welcome if they contain suggested
replacement text.
--
Aahz (aa**@pythoncra ft.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************ ********@comcas t.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
documentati on 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
14791
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 the toolbar or the context menu? I'm aware that I can not stop a refresh, but the reason I want to know is that I have a hidden frame in an intranet application. This hidden frame is present at all times after
2
636
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 null all the references I have to objects in the AppDomain. Any idea?
1
1481
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 = new OleDbCommand(sql,con);
1
3066
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 stateInfo) at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse) at ..." It doesn't interfere with the functionality and is transparent, and the only
0
1053
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 was being aborted" Now I would like to process the rest of the page but since the timeout occurs I cant. Is there any possibility to get rid of the timeout? I already set the buffer to false and increased the timeout time. Please advise me.
1
662
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 form declares an instance of a data-layer class with form-level scope Protected WithEvents MyDataLayer as DataLayer -- and a new instance of the class is created in Page_Load:
0
1063
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 but suddenly stops at about 1 min 45-50 secs time. The import stops and the error is "Thread was being aborted". The whole stuff works fine when i connect to the database server from local machine.
5
2840
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 aborted" error when this method is called.
0
8797
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9309
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9171
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4717
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2107
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.