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

Skip to content

Commit 119479f

Browse files
committed
Issue20467: clarify __init__'s role
1 parent 72c2a0f commit 119479f

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
@@ -1081,13 +1081,17 @@ Basic customization
10811081

10821082
.. index:: pair: class; constructor
10831083

1084-
Called when the instance is created. The arguments are those passed to the
1085-
class constructor expression. If a base class has an :meth:`__init__` method,
1086-
the derived class's :meth:`__init__` method, if any, must explicitly call it to
1087-
ensure proper initialization of the base class part of the instance; for
1088-
example: ``BaseClass.__init__(self, [args...])``. As a special constraint on
1089-
constructors, no value may be returned; doing so will cause a :exc:`TypeError`
1090-
to be raised at runtime.
1084+
Called after the instance has been created (by :meth:`__new__`), but before
1085+
it is returned to the caller. The arguments are those passed to the
1086+
class constructor expression. If a base class has an :meth:`__init__`
1087+
method, the derived class's :meth:`__init__` method, if any, must explicitly
1088+
call it to ensure proper initialization of the base class part of the
1089+
instance; for example: ``BaseClass.__init__(self, [args...])``.
1090+
1091+
Because :meth:`__new__` and :meth:`__init__` work together in constructing
1092+
objects (:meth:`__new__` to create it, and :meth:`__init__` to customise it),
1093+
no non-``None`` value may be returned by :meth:`__init__`; doing so will
1094+
cause a :exc:`TypeError` to be raised at runtime.
10911095

10921096

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

0 commit comments

Comments
 (0)