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: Error in __new__ docs
Type: Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Kevin Shweh, docs@python, lukasz.langa, miss-islington, rhettinger, serhiy.storchaka, veky
Priority: normal Keywords: patch

Created on 2021-09-04 22:38 by Kevin Shweh, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28210 merged rhettinger, 2021-09-07 15:34
PR 28211 merged miss-islington, 2021-09-07 16:04
PR 28212 merged miss-islington, 2021-09-07 16:04
PR 28213 merged miss-islington, 2021-09-07 16:04
Messages (9)
msg401065 - (view) Author: Kevin Shweh (Kevin Shweh) Date: 2021-09-04 22:38
The data model docs for __new__ say "If __new__() is invoked during object construction and it returns an instance or subclass of cls, then the new instance’s __init__() method will be invoked..."

"instance or subclass of cls" is incorrect - if for some reason __new__ returns a subclass of cls, __init__ will not be invoked, unless the subclass also happens to be an instance of cls (which can happen with metaclasses).

This should probably say something like "instance of cls (including subclass instances)", or "instance of cls or of a subclass of cls", or just "instance of cls".
msg401198 - (view) Author: Vedran Čačić (veky) * Date: 2021-09-07 01:14
The first variant seems best to me.
msg401210 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-09-07 06:00
I would be happy with just "instance of cls".  Elsewhere in the docs, that phrasing almost always means "instance of a cls or instance of a subclass of cls".  Also, it is consistent with the meaning of isinstance(inst, cls) unless overridden by ABC logic.
msg401214 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-07 06:52
I concur with Raymond. Originally it was "instance of cls". It was changed in issue15542 (6b16d938d6d1ccb443815e20e8812deed274dc09).
msg401294 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-07 16:04
New changeset fa15df77f02ba4a66ba0b71989381a426038be01 by Raymond Hettinger in branch 'main':
bpo-45104: Clarify when __init__ is called (GH-28210)
https://github.com/python/cpython/commit/fa15df77f02ba4a66ba0b71989381a426038be01
msg401298 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-07 16:21
New changeset 5a42a49477cd601d67d81483f9589258dccb14b1 by Miss Islington (bot) in branch '3.8':
bpo-45104: Clarify when __init__ is called (GH-28210) (GH-28213)
https://github.com/python/cpython/commit/5a42a49477cd601d67d81483f9589258dccb14b1
msg401299 - (view) Author: miss-islington (miss-islington) Date: 2021-09-07 16:26
New changeset ef704137770b2e98da7880c828aaf921f0b45337 by Miss Islington (bot) in branch '3.10':
bpo-45104: Clarify when __init__ is called (GH-28210)
https://github.com/python/cpython/commit/ef704137770b2e98da7880c828aaf921f0b45337
msg401300 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-07 16:27
New changeset b1f2fe777e1fe133d33cd1e714b8aa0f81fed1cc by Miss Islington (bot) in branch '3.9':
bpo-45104: Clarify when __init__ is called (GH-28210) (GH-28212)
https://github.com/python/cpython/commit/b1f2fe777e1fe133d33cd1e714b8aa0f81fed1cc
msg401302 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-07 16:27
Thanks for the patch, Raymond!
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89267
2021-09-07 16:27:51lukasz.langasetstatus: open -> closed
resolution: fixed
messages: + msg401302

stage: patch review -> resolved
2021-09-07 16:27:31lukasz.langasetmessages: + msg401300
2021-09-07 16:26:42miss-islingtonsetmessages: + msg401299
2021-09-07 16:21:27lukasz.langasetmessages: + msg401298
2021-09-07 16:04:57miss-islingtonsetpull_requests: + pull_request26638
2021-09-07 16:04:53miss-islingtonsetpull_requests: + pull_request26637
2021-09-07 16:04:48miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request26636
2021-09-07 16:04:43lukasz.langasetnosy: + lukasz.langa
messages: + msg401294
2021-09-07 15:34:38rhettingersetkeywords: + patch
stage: patch review
pull_requests: + pull_request26635
2021-09-07 06:52:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg401214
2021-09-07 06:00:42rhettingersetnosy: + rhettinger
messages: + msg401210
2021-09-07 01:14:18vekysetnosy: + veky
messages: + msg401198
2021-09-04 22:38:45Kevin Shwehcreate