mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Issue20467: clarify __init__'s role
This commit is contained in:
parent
72c2a0f60a
commit
119479f705
1 changed files with 11 additions and 7 deletions
|
|
@ -1081,13 +1081,17 @@ Basic customization
|
||||||
|
|
||||||
.. index:: pair: class; constructor
|
.. index:: pair: class; constructor
|
||||||
|
|
||||||
Called when the instance is created. The arguments are those passed to the
|
Called after the instance has been created (by :meth:`__new__`), but before
|
||||||
class constructor expression. If a base class has an :meth:`__init__` method,
|
it is returned to the caller. The arguments are those passed to the
|
||||||
the derived class's :meth:`__init__` method, if any, must explicitly call it to
|
class constructor expression. If a base class has an :meth:`__init__`
|
||||||
ensure proper initialization of the base class part of the instance; for
|
method, the derived class's :meth:`__init__` method, if any, must explicitly
|
||||||
example: ``BaseClass.__init__(self, [args...])``. As a special constraint on
|
call it to ensure proper initialization of the base class part of the
|
||||||
constructors, no value may be returned; doing so will cause a :exc:`TypeError`
|
instance; for example: ``BaseClass.__init__(self, [args...])``.
|
||||||
to be raised at runtime.
|
|
||||||
|
Because :meth:`__new__` and :meth:`__init__` work together in constructing
|
||||||
|
objects (:meth:`__new__` to create it, and :meth:`__init__` to customise it),
|
||||||
|
no non-``None`` value may be returned by :meth:`__init__`; doing so will
|
||||||
|
cause a :exc:`TypeError` to be raised at runtime.
|
||||||
|
|
||||||
|
|
||||||
.. method:: object.__del__(self)
|
.. method:: object.__del__(self)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue