Issue 15243: Misleading documentation for prepare (original) (raw)

Issue15243

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: JelleZijlstra, William.Schwartz, alclarks, benedwards14, berker.peksag, brandtbucher, daniel.urban, docs@python, eric.araujo, jaysinh.shukla, ncoghlan
Priority: normal Keywords: easy, patch

Created on 2012-07-03 15:08 by William.Schwartz, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_metaclass.py William.Schwartz,2012-07-03 15:30 Test to demonstrate implicit staticmethodness of __prepare__
issue15243_diff_python3.5_3.6_v1.diff jaysinh.shukla,2016-06-17 11:04 review
Pull Requests
URL Status Linked Edit
PR 17124 merged alclarks,2019-11-12 14:59
PR 18185 merged miss-islington,2020-01-25 18:50
PR 18186 merged miss-islington,2020-01-25 18:50
Messages (13)
msg164606 - (view) Author: William Schwartz (William.Schwartz) * Date: 2012-07-03 15:08
Section 3.3.3.2. "Preparing the class namespace" of the documentation (http://docs.python.org/dev/reference/datamodel.html#preparing-the-class-namespace) states that "If the metaclass has a __prepare__ attribute, it is called as ``namespace = metaclass.__prepare__(name, bases, **kwds)``...." This isn't quite true. By just defining a ``__prepare__`` method in a metaclass, the interpreter calls it as it would a static method -- there is no implicit first argument referring to ``metaclass`` as the documentation implies. The documentation should be amended to say that users can decorate ``__prepare__`` as a class method to get ``metaclass`` passed in as the implicit first argument.
msg164607 - (view) Author: William Schwartz (William.Schwartz) * Date: 2012-07-03 15:30
Attached a unittest script to demonstrate that __prepare__ is implicitly a staticmethod.
msg164685 - (view) Author: Daniel Urban (daniel.urban) * (Python triager) Date: 2012-07-05 16:47
__prepare__ is not implicitly a staticmethod, and it is called exactly as documented (also in types.prepare_class). There is no implicit first argument because the method is called on the (meta)class object.
msg164696 - (view) Author: William Schwartz (William.Schwartz) * Date: 2012-07-05 19:59
Daniel, Good point. However it would still be useful for documentation to point out that __prepare__ can be passed the metaclass as the implicit first argument by being decorated by classmethod. I'll post a small patch when I get a chance to add a sentence saying as much in the documentation and reorganize the test cases in Lib/test/test_metaclass.py to make it part of the narrative of the doctests.
msg164697 - (view) Author: Daniel Urban (daniel.urban) * (Python triager) Date: 2012-07-05 20:52
Actually the docs contained a similar sentence ("If the metaclass has a :meth:`__prepare__` attribute (usually implemented as a class or static method), ..."), but it was removed in befd56673c80 when Nick rewrote this section.
msg221871 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-29 18:08
Does the documentation need amending, yes or no?
msg267459 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2016-06-05 19:00
I think the current documentation is correct and doesn't need changes. There is also already an example of a working __prepare__ method.
msg268356 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-12 09:51
The documentation should mention that the __prepare__ method must be implemented as a classmethod (see for the reference.) The example at https://docs.python.org/dev/reference/datamodel.html#metaclass-example needs to be linked from the "Preparing the class namespace" section.
msg268719 - (view) Author: Jaysinh shukla (jaysinh.shukla) * Date: 2016-06-17 11:04
Submitting patch according to this (http://bugs.python.org/issue15243#msg268356) message. Thanks!
msg355470 - (view) Author: Benjamin Edwards (benedwards14) * Date: 2019-10-27 15:06
Is this still open, does the patch still need a pull request?
msg360697 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2020-01-25 18:50
New changeset 7de617455ed788e6730c40cf854c4b72b0432194 by Berker Peksag (alclarks) in branch 'master': bpo-15243: Document __prepare__ as classmethod (GH-17124) https://github.com/python/cpython/commit/7de617455ed788e6730c40cf854c4b72b0432194
msg360698 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2020-01-25 19:04
New changeset 321491a536c378227f9d574703f7c06f89c67dcf by Berker Peksag (Miss Islington (bot)) in branch '3.8': bpo-15243: Document __prepare__ as classmethod (GH-17124) https://github.com/python/cpython/commit/321491a536c378227f9d574703f7c06f89c67dcf
msg360699 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2020-01-25 19:04
New changeset 548685e364af3d366d3aef924b2077ee6f8d13dc by Berker Peksag (Miss Islington (bot)) in branch '3.7': bpo-15243: Document __prepare__ as classmethod (GH-17124) https://github.com/python/cpython/commit/548685e364af3d366d3aef924b2077ee6f8d13dc
History
Date User Action Args
2022-04-11 14:57:32 admin set github: 59448
2020-01-25 19:05:38 berker.peksag set status: open -> closedstage: patch review -> resolvedresolution: fixedversions: + Python 3.7, Python 3.8, Python 3.9, - Python 3.5, Python 3.6
2020-01-25 19:04:59 berker.peksag set messages: +
2020-01-25 19:04:20 berker.peksag set messages: +
2020-01-25 18:50:19 miss-islington set pull_requests: + <pull%5Frequest17569>
2020-01-25 18:50:13 miss-islington set pull_requests: + <pull%5Frequest17568>
2020-01-25 18:50:03 berker.peksag set messages: +
2019-11-12 15:04:07 alclarks set nosy: + alclarks
2019-11-12 14:59:58 alclarks set stage: needs patch -> patch reviewpull_requests: + <pull%5Frequest16632>
2019-11-04 16:53:25 brandtbucher set nosy: + brandtbucher
2019-10-27 15:06:42 benedwards14 set nosy: + benedwards14messages: +
2016-06-17 11:04:37 jaysinh.shukla set files: + issue15243_diff_python3.5_3.6_v1.diffnosy: + jaysinh.shuklamessages: + keywords: + patch
2016-06-12 09:51:54 berker.peksag set nosy: + berker.peksagmessages: +
2016-06-05 19:00:54 JelleZijlstra set nosy: + JelleZijlstramessages: +
2016-06-03 08:54:58 BreamoreBoy set nosy: - BreamoreBoy
2016-06-03 04:22:56 berker.peksag set keywords: + easyversions: + Python 3.6, - Python 3.4
2016-06-03 04:21:51 berker.peksag link issue17352 superseder
2014-06-29 18:08:31 BreamoreBoy set versions: + Python 3.4, Python 3.5, - Python 3.2, Python 3.3nosy: + BreamoreBoymessages: + components: - Tests
2012-07-05 20:52:19 daniel.urban set messages: +
2012-07-05 19:59:06 William.Schwartz set messages: +
2012-07-05 16:47:07 daniel.urban set messages: +
2012-07-05 16:35:52 eric.araujo set nosy: + ncoghlan, eric.araujostage: needs patchversions: + Python 3.2
2012-07-03 17:25:37 daniel.urban set nosy: + daniel.urban
2012-07-03 15:30:12 William.Schwartz set files: + test_metaclass.pymessages: +
2012-07-03 15:08:37 William.Schwartz create