[issue21415] Python __new__ method doc typo (it's a class and not a static method)
Eric Snow
report at bugs.python.org
Tue May 13 03:03:38 CEST 2014
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:
class Spam(int):
def __new__(cls, value):
self = super().__new__(Spam, value)
self._eggs = 10
return self
Spam is passed in instead of int (as would happen if it were a classmethod), resulting in extra memory being allocated for _eggs (and for __dict__ among other things).
----------
nosy: +eric.snow
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21415>
_______________________________________
More information about the Python-bugs-list
mailing list