[Python-Dev] Make class_getitem a class method (original) (raw)
Yury Selivanov yselivanov.ml at gmail.com
Fri Dec 15 13:02:53 EST 2017
- Previous message (by thread): [Python-Dev] Make __class_getitem__ a class method
- Next message (by thread): [Python-Dev] Make __class_getitem__ a class method
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Dec 15, 2017 at 12:45 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
15.12.17 18:47, Yury Selivanov пише:
Shouldn't we optimize the usability for pure-Python first, and then for C API? Right now we have the 'new' magic method, which isn't a @classmethod. Making 'classgetitem' a @classmethod will confuse regular Python users. For example: class Foo: def new(cls, ...): pass @classmethod def classgetitem(cls, item): pass To me it makes sense that type methods that are supposed to be called on type by the Python interpreter don't need the classmethod decorator. METHSTATIC is a public working API, and in my opinion it's totally fine if we use it. It's not even hard to use it, it's just mildly inconvenient at most. new is not a class method, it is an "automatic" static method.
I never said that new is a class method :)
The following two declarations are equivalent:
class A: def new(cls): return cls.name class B: @staticmethod def new(cls): return cls.name
But nobody decorates new with a @staticmethod. And making class_getitem a @classmethod will only confuse users -- that's all I'm saying.
So I'm +1 to keep the things exactly as they are now. It would be great do document that in order to implement class_getitem in C one should add it as METH_STATIC. I also think we should merge your PR that tests that it works the way it's expected.
Yury
- Previous message (by thread): [Python-Dev] Make __class_getitem__ a class method
- Next message (by thread): [Python-Dev] Make __class_getitem__ a class method
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]