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: Be clear that __prepare__ must be declared as a class method
Type: Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Misleading documentation for __prepare__
View: 15243
Assigned To: docs@python Nosy List: berker.peksag, docs@python, ncoghlan
Priority: normal Keywords:

Created on 2013-03-04 15:11 by ncoghlan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg183463 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-03-04 15:11
The docs on __prepare__ don't make it clear that it should be a staticmethod, and the error message if you forget is not obvious at all. (This is particularly so, since the examples in PEP 3115 had it as an ordinary method).
msg183466 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-03-04 15:28
Class method, not static method (super() breaks if you declare it as a static method)
msg237095 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-03-03 00:10
Should __prepare__ be special-cased as a classmethod, like __new__ is?  Is there any reason to ever have __prepare__ /not/ be a classmethod?
msg237127 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-03-03 12:36
__new__ is a little weird - it's actually special cased as a staticmethod.

Your questions is still valid, though.

For existing versions, documenting the requirement is the only option. 

For future versions, we could conceivably implement a "decorate it if it isn't already decorated" fallback, but for backwards compatibility we'd have to avoid double-decorating explicitly decorated implementations.
msg267032 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-03 04:21
This is a duplicate of issue 15243.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61554
2016-06-03 04:21:51berker.peksagsetstatus: open -> closed

superseder: Misleading documentation for __prepare__

nosy: + berker.peksag
messages: + msg267032
resolution: duplicate
stage: resolved
2015-07-21 07:27:01ethan.furmansetnosy: - ethan.furman
2015-03-03 12:36:22ncoghlansetmessages: + msg237127
2015-03-03 00:10:20ethan.furmansetmessages: + msg237095
2014-05-19 01:29:23ethan.furmansetnosy: + ethan.furman
2013-10-13 20:16:56georg.brandlsetassignee: docs@python

components: + Documentation
nosy: + docs@python
2013-03-04 15:28:05ncoghlansetmessages: + msg183466
title: Be clear that __prepare__ must be declared as a static method -> Be clear that __prepare__ must be declared as a class method
2013-03-04 15:11:32ncoghlancreate