Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65168 > unrolled thread

Re: __init__ is the initialiser

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-01-31 21:40 -0500
Last post2014-01-31 21:40 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: __init__ is the initialiser Terry Reedy <tjreedy@udel.edu> - 2014-01-31 21:40 -0500

#65168 — Re: __init__ is the initialiser

FromTerry Reedy <tjreedy@udel.edu>
Date2014-01-31 21:40 -0500
SubjectRe: __init__ is the initialiser
Message-ID<mailman.6246.1391222450.18130.python-list@python.org>
On 1/31/2014 7:13 PM, Ethan Furman wrote:
> On 01/31/2014 03:47 PM, Ben Finney wrote:
>>
>> I would prefer it to be clear that “__init__” is called automatically,
>> *during* the constructor's operation. So, instead of:
>>
>>      Called when the instance is created.
>>
>> I suggest:
>>
>>      Called automatically by the constructor “__new__” during instance
>>      creation, to initialise the new instance.
>
> But __new__ does not call __init__, type does [1].

If the class is an instance of type, it is type.__call__,

 >>> tuple.__call__
<method-wrapper '__call__' of type object at 0x0000000067E8ED30>

I presume it is basically something like this:

class type:
   def __call__(self, *args, **kwds):
     instance = self.__new__(cls, *args, **kwds)
     self.__init__(instance, *args, **kwds)
     return instance

.__new__ and .__init__ are the plugins used by the true class instance 
constructor.

-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web