Message217749
Actually, no, it is a staticmethod. See Guido's tutorial from way back in version 2.2:
[quote]
__new__ is a static method. When defining it, you don't need to (but may!) use the phrase "__new__ = staticmethod(__new__)", because this is implied by its name (it is special-cased by the class constructor).
[end quote]
https://www.python.org/download/releases/2.2.3/descrintro
I believe that this explains why you have to use this idiom inside __new__ when using super():
def __new__(cls, x):
super().__new__(cls, x)
If __new__ were a classmethod, the first argument "cls" would be provided automatically.
If you try making __new__ a classmethod, it breaks:
py> class Test:
... @classmethod
... def __new__(cls):
... pass
...
py> x = Test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __new__() takes 1 positional argument but 2 were given
whereas a staticmethod works fine. |
|
Date |
User |
Action |
Args |
2014-05-02 12:07:35 | steven.daprano | set | recipients:
+ steven.daprano, docs@python, Jurko.Gospodnetić |
2014-05-02 12:07:35 | steven.daprano | set | messageid: <1399032455.08.0.160204449904.issue21415@psf.upfronthosting.co.za> |
2014-05-02 12:07:35 | steven.daprano | link | issue21415 messages |
2014-05-02 12:07:34 | steven.daprano | create | |
|