473,770 Members | 3,398 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 1494
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
14795
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
1485
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
3080
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
1057
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
1066
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
2842
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
9591
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
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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
10057
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...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
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
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6676
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();...
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.