Python中super()或object.__new__报TypeError: object.__new__() takes no arguments错误的解决方案

出现这种情况是调用object类__new__方法参数传递多了导致:
一般是使用了类似super().new(cls,*args,**kwargs)
或object.new(self,*args,**kwargs)
这种方式调用的,此时只要改成:
super().new(cls) 或object.new(self)
调用就可以了。
注意:如果直接父类不是object,通过super调用服了的__new__方法,需要看直接父类的参数才知怎么传递参数,因此老猿建议使用object的__new__方法调用。
相关问题请大家参考: Python类中的__new__方法深入剖析:调用父类__new__方法参数的困惑

原文地址:https://www.cnblogs.com/LaoYuanPython/p/11087678.html