From: Ethan Furman Date: Thu, 15 Jan 2015 06:02:10 +0000 (-0800) Subject: Issue20467: clarify __init__'s role X-Git-Tag: v2.7.10rc1~229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3700cc3ad66de1c7b98e1d1e73eeddaa24da1fa0;p=python Issue20467: clarify __init__'s role --- diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 5a6c763769..44901af718 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1225,13 +1225,17 @@ Basic customization .. 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 + 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...])``. As a special constraint on - constructors, no value may be returned; doing so will cause a :exc:`TypeError` - to be raised at runtime. + 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)