Eric Snow added the comment:
FYI, __new__() is a staticmethod to accommodate subclassing. Several things
that happen at instantiation-time (when __new__() is called), including memory
allocation, are tied to the class that is passed in and may be different for
subclasses. For example:
Changes by Jesús Cea Avión j...@jcea.es:
--
nosy: +jcea
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21415
___
___
Python-bugs-list mailing list
Jurko Gospodnetić added the comment:
Thanks for the detailed response! :-(
I should have tested more before reporting the issue.
Sorry for the noise. :-(
I saw the 'cls' argument and assumed it was a class
method. Having to explicitly specify cls did not
seem to be in contradiction with this
New submission from Jurko Gospodnetić:
Doc/reference/datamodel.rst documentation states that
the __new__ method is a static method (in Python, not
in C!) when it is in fact a class method.
A patch has been prepared in the
https://bitbucket.org/jurko/cpython repository.
branch:
Changes by Jurko Gospodnetić jurko.gospodne...@gmail.com:
--
keywords: +patch
Added file: http://bugs.python.org/file35130/81c5ba188805.diff
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21415
Steven D'Aprano added the comment:
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
eryksun added the comment:
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)
Yes, if __new__ is defined and is a function, type_new replaces it with a
staticmethod: