I noticed that a definition of __new__
begins as follows:
def __new__(cls, *args, **kw):
# This is needed because object.__new__ only accepts
# the cls argument.
new_meth = super().__new__
if new_meth is object.__new__:
inst = new_meth(cls)
else:
inst = new_meth(cls, **kw)
Is this standard? Testing for method identity seems weird. Why doesn't object.__new__
just ignore arguments other than the cls
? What method is normally run when __new__
is called on a class — if it's object.__new__
then does the bytecode generator just not push the arguments onto the stack?