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: http://hg.python.org/cpython/file/04f714765c13/Objects/typeobject.c#l2437 For example: >>> class A: __new__ = lambda c: 0 >>> type(vars(A)['__new__']) <class 'staticmethod'> A heap type that defines __new__ has tp_new set to slot_tp_new. This looks up and calls __new__, with the class inserted as the first argument: http://hg.python.org/cpython/file/04f714765c13/Objects/typeobject.c#l6036 If you use a classmethod, looking up __new__ returns a method bound to the class. When called, this inserts the class in the args yet again: http://hg.python.org/cpython/file/04f714765c13/Objects/classobject.c#l321 ---------- nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21415> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com