我知道当我们通过super方法调用parent的方法时,我们可以忽略绑定方法中的"self"参数,如下所示:
class Foo(object):
def __init__(self):
super(Foo, self).__init__() # We needn't pass in the "self" argument
# ...
Run Code Online (Sandbox Code Playgroud)
但__new__方法有所不同:
class Bar(object):
def __new__(cls, *args, **kwargs):
return super(Bar, cls).__new__(cls, *args, **kwargs) # Why need a "cls" argument?
Run Code Online (Sandbox Code Playgroud)