[Python-checkins] cpython (2.7): Issue20467: clarify __init__'s role

ethan.furman python-checkins at python.org
Thu Jan 15 07:02:41 CET 2015


https://hg.python.org/cpython/rev/7972b18b6e42
changeset:   94152:7972b18b6e42
branch:      2.7
parent:      94147:38826e21f0db
user:        Ethan Furman <ethan at stoneleaf.us>
date:        Wed Jan 14 22:02:10 2015 -0800
summary:
  Issue20467: clarify __init__'s role

files:
  Doc/reference/datamodel.rst |  12 ++++++++----
  1 files changed, 8 insertions(+), 4 deletions(-)


diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1225,13 +1225,17 @@
 
    .. 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)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list