__init__ is the initialiser

M

Mark Lawrence

From http://docs.python.org/3/reference/datamodel.html#object.__init__
which states:-

"
Called when the instance is created. The arguments are those passed to
the class constructor expression. If a base class has an __init__()
method, the derived class’s __init__() method, if any, must explicitly
call it to ensure proper initialization of the base class part of the
instance; for example: BaseClass.__init__(self, [args...]). As a special
constraint on constructors, no value may be returned; doing so will
cause a TypeError to be raised at runtime.
"

Should the wording of the above be changed to clearly reflect that we
have an initialiser here and that __new__ is the constructor?
 
G

Gregory Ewing

Mark said:
Called when the instance is created. The arguments are those passed to
the class constructor expression. If a base class has an __init__()
method, the derived class’s __init__() method, if any, must explicitly
call it to ensure proper initialization of the base class part of the
instance; for example: BaseClass.__init__(self, [args...]). As a special
constraint on constructors, no value may be returned; doing so will
cause a TypeError to be raised at runtime.
"

Should the wording of the above be changed to clearly reflect that we
have an initialiser here and that __new__ is the constructor?

The first instance of "constructor" in that paragraph refers
to the expression used to instantiate an object, e.g.
'MyClass(foo, blarg)', which is fine.

The second instance might be clearer if it said "as a special
constraint on the __init__ method" and avoided the word
"constructor" altogether.

Generally I think it would be better to talk about "the
__new__ method" and "the __init__ method", and not call
either of them a constructor.
 
R

Roy Smith

Gregory Ewing said:
Generally I think it would be better to talk about "the
__new__ method" and "the __init__ method", and not call
either of them a constructor.

+1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top