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 '__class_getitem__' a @classmethod will confuse > regular Python users. For example: > > class Foo: > def __new__(cls, ...): pass > > @classmethod > def __class_getitem__(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. > > METH_STATIC 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. >>> class C: ... def __new__(cls): return object.__new__(cls) ... >>> C().__new__ is C.__new__ True >>> C.__dict__['__new__'] <staticmethod object at 0x7f664ae82c20> The following two declarations are equivalent: class A: def __new__(cls): return cls.__name__ class B: @staticmethod def __new__(cls): return cls.__name__
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4