Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion __new__
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alex Martelli  
View profile  
 More options Nov 6 2005, 11:12 am
Newsgroups: comp.lang.python
From: al...@mail.comcast.net (Alex Martelli)
Date: Sun, 6 Nov 2005 08:12:19 -0800
Local: Sun, Nov 6 2005 11:12 am
Subject: Re: __new__
Peter Otten <__pete...@web.de> wrote:

   ...

> is as __new__ had left it). Thus, for a new-style class C, the statement
> x=C(23) is equivlent to the following code:

>     x = C.__new__(C, 23)
>     if isinstance(x, C): C.__init__(x, 23)
   ...
> the "Nutshell" example should be changed to

>     x = C.__new__(C, 23)
>     if isinstance(x, C): x.__init__(23)

> to comply with the current implementation (I used Python 2.4).

Hmmm -- not quite, because in the new-style object model special methods
are taken from the type, NOT from the instance as the latter is saying.
E.g, if you change class B into:

class B(A):
    def __init__(self):
        print "init B"
        def f(): print 'from instance'
        self.__init__ = f

you'll see that while b.__init__() would print 'from instance',
instantiating A will not.  I think the right correction to the Nutshell
is therefore:

     x = C.__new__(C, 23)
     if isinstance(x, C): type(x).__init__(x, 23)

and this is how I plan to have it in the 2nd edition.

Alex


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google