[Python-Dev] init_subclass is a class method (Was: Make class_getitem a class method) (original) (raw)
Ivan Levkivskyi levkivskyi at gmail.com
Fri Dec 15 17:48:10 EST 2017
- Previous message (by thread): [Python-Dev] __init_subclass__ is a class method (Was: Make __class_getitem__ a class method)
- Next message (by thread): [Python-Dev] __init_subclass__ is a class method (Was: Make __class_getitem__ a class method)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 15 December 2017 at 18:40, Serhiy Storchaka <storchaka at gmail.com> wrote:
15.12.17 19:04, Ivan Levkivskyi пише:
Good point! Pure Python will be the primary use case and we have another precedent for "automatic" class method: initsubclass (it does not need to be decorated).
initsubclass is very different beast, and parallels with it can be confusing. It is automatically decorated with classmethod if it is a regular function implemented in C. The following two examples are totally equivalent: class A: def initsubclass(cls): pass class B: @classmethod def initsubclass(cls): pass help(A) shows initsubclass() as a class method (in 3.7). But if you implement the class in C you need to make initsubclass a class method. I think initsubclass should be documented as a class method since it is a class method.
Thank you for clarification!
Actually documentation
https://docs.python.org/3.6/reference/datamodel.html#customizing-class-creation
already says classmethod object.__init_subclass__(cls)
I am not an expert in this, so I am not sure if the docs can be improved
here (maybe we can add how this works with C API?)
-- Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171215/681c40c5/attachment-0001.html>
- Previous message (by thread): [Python-Dev] __init_subclass__ is a class method (Was: Make __class_getitem__ a class method)
- Next message (by thread): [Python-Dev] __init_subclass__ is a class method (Was: Make __class_getitem__ a class method)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]