Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 845d33c

Browse files
committed
Issue20467: clarify __init__'s role
2 parents 562b7cb + 119479f commit 845d33c

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Doc/reference/datamodel.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,17 @@ Basic customization
11001100

11011101
.. index:: pair: class; constructor
11021102

1103-
Called when the instance is created. The arguments are those passed to the
1104-
class constructor expression. If a base class has an :meth:`__init__` method,
1105-
the derived class's :meth:`__init__` method, if any, must explicitly call it to
1106-
ensure proper initialization of the base class part of the instance; for
1107-
example: ``BaseClass.__init__(self, [args...])``. As a special constraint on
1108-
constructors, no value may be returned; doing so will cause a :exc:`TypeError`
1109-
to be raised at runtime.
1103+
Called after the instance has been created (by :meth:`__new__`), but before
1104+
it is returned to the caller. The arguments are those passed to the
1105+
class constructor expression. If a base class has an :meth:`__init__`
1106+
method, the derived class's :meth:`__init__` method, if any, must explicitly
1107+
call it to ensure proper initialization of the base class part of the
1108+
instance; for example: ``BaseClass.__init__(self, [args...])``.
1109+
1110+
Because :meth:`__new__` and :meth:`__init__` work together in constructing
1111+
objects (:meth:`__new__` to create it, and :meth:`__init__` to customise it),
1112+
no non-``None`` value may be returned by :meth:`__init__`; doing so will
1113+
cause a :exc:`TypeError` to be raised at runtime.
11101114

11111115

11121116
.. method:: object.__del__(self)

0 commit comments

Comments
 (0)