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.

Author steven.daprano
Recipients Jurko.Gospodnetić, docs@python, steven.daprano
Date 2014-05-02.12:07:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1399032455.08.0.160204449904.issue21415@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-05-02 12:07:35steven.dapranosetrecipients: + steven.daprano, docs@python, Jurko.Gospodnetić
2014-05-02 12:07:35steven.dapranosetmessageid: <1399032455.08.0.160204449904.issue21415@psf.upfronthosting.co.za>
2014-05-02 12:07:35steven.dapranolinkissue21415 messages
2014-05-02 12:07:34steven.dapranocreate