diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2015-01-15 05:57:15 (GMT) |
---|---|---|
committer | Ethan Furman <ethan@stoneleaf.us> | 2015-01-15 05:57:15 (GMT) |
commit | 9fdb0fe17b6d3f3ff7ba8e173c1835bb3ad50686 (patch) | |
tree | c604a1f790efaa94dcb6410cd1ad28ffbc53c0de /Doc/reference | |
parent | 71f1c5c49646c365407c4686bf377b967f2f43b3 (diff) | |
parent | 845d33c526b6e6408cb75a4a66488d4c87200716 (diff) | |
download | cpython-9fdb0fe17b6d3f3ff7ba8e173c1835bb3ad50686.zip cpython-9fdb0fe17b6d3f3ff7ba8e173c1835bb3ad50686.tar.gz cpython-9fdb0fe17b6d3f3ff7ba8e173c1835bb3ad50686.tar.bz2 |
Issue20467: clarify __init__'s role
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/datamodel.rst | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 7a6ed0a..5e909a9 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1100,13 +1100,17 @@ Basic customization .. index:: pair: class; constructor - Called when the instance is created. The arguments are those passed to the - class constructor expression. If a base class has an :meth:`__init__` method, - the derived class's :meth:`__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 :exc:`TypeError` - to be raised at runtime. + Called after the instance has been created (by :meth:`__new__`), but before + it is returned to the caller. The arguments are those passed to the + class constructor expression. If a base class has an :meth:`__init__` + method, the derived class's :meth:`__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...])``. + + 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) |