This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Confusing wording about __init__
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ethan.furman, python-dev, simeon.visser
Priority: normal Keywords: patch

Created on 2014-01-31 22:41 by BreamoreBoy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue20467.stoneleaf.01.patch ethan.furman, 2014-11-23 16:43 review
Messages (6)
msg209843 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-01-31 22:41
I found the wording here http://docs.python.org/3/reference/datamodel.html#object.__init__ very confusing as it implies that __init__ is the class constructor and not the initialiser.  Specifically it says "As a special constraint on constructors, no value may be returned; doing so will cause a TypeError to be raised at runtime".  Can we please have the wording changed so that it states exactly what this method does?  Possibly changes are also needed in the equivalent section for __new__.
msg231570 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-11-23 16:43
Thoughts?
msg231903 - (view) Author: Simeon Visser (simeon.visser) Date: 2014-11-30 20:34
Is it worth clarifying that __init__ can return a value but only the value None? The following won't raise a TypeError:

class O(object):
    def __init__(self):
        return None

Admittedly the "return None" is the default behaviour but people may attempt this in order to "block creation" of the instance (as __new__ is less well-known, I have seen the above attempted on Stack Overflow: http://stackoverflow.com/questions/26896941/proper-way-to-terminate-object-creation-inside-of-init/)
msg234054 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-15 05:58
New changeset 94696e457461 by Ethan Furman in branch '3.3':
Issue20467: clarify __init__'s role
https://hg.python.org/cpython/rev/94696e457461

New changeset 46c9b34f31b8 by Ethan Furman in branch '3.4':
Issue20467: clarify __init__'s role
https://hg.python.org/cpython/rev/46c9b34f31b8

New changeset d0421de8ee11 by Ethan Furman in branch 'default':
Issue20467: clarify __init__'s role
https://hg.python.org/cpython/rev/d0421de8ee11
msg234056 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-15 06:02
New changeset 7972b18b6e42 by Ethan Furman in branch '2.7':
Issue20467: clarify __init__'s role
https://hg.python.org/cpython/rev/7972b18b6e42
msg234057 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-01-15 06:05
Changed 'no value may be returned' to 'no non-None value may be returned'.
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64666
2015-01-15 06:05:55ethan.furmansetstatus: open -> closed
resolution: fixed
messages: + msg234057

stage: patch review -> resolved
2015-01-15 06:02:56python-devsetmessages: + msg234056
2015-01-15 05:58:30python-devsetnosy: + python-dev
messages: + msg234054
2014-11-30 20:34:25simeon.vissersetnosy: + simeon.visser
messages: + msg231903
2014-11-23 16:43:33ethan.furmansetfiles: + issue20467.stoneleaf.01.patch
versions: + Python 3.5
messages: + msg231570

keywords: + patch
stage: patch review
2014-02-03 15:39:35BreamoreBoysetnosy: - BreamoreBoy
2014-01-31 23:51:56ethan.furmansetnosy: + ethan.furman
2014-01-31 22:41:34BreamoreBoycreate