Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65168
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: __init__ is the initialiser |
| Date | 2014-01-31 21:40 -0500 |
| References | <52EC0E3C.5070900@stoneleaf.us> <20140131224507.GA5454@cskk.homeip.net> <85ob2rhfxd.fsf@benfinney.id.au> <52EC3C14.8080806@stoneleaf.us> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6246.1391222450.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: __init__ is the initialiser Terry Reedy <tjreedy@udel.edu> - 2014-01-31 21:40 -0500
csiph-web