Python __new\uuux=TypeError:object()不接受任何参数

Python __new\uuux=TypeError:object()不接受任何参数,python,class,object,pygame,Python,Class,Object,Pygame,我希望我的类能够自己创建对象,我发现这在“new”中是可能的,但显然它不起作用,因为我遇到了以下错误: 类型错误:object()不接受任何参数 这就是我正在使用的类,我会发布所有的类,以防它们来自代码的另一部分 class Planete: def __new__(cls, rayon, periode, envergure,look): print("test __new__ of the class {}".format(cls)) retu

我希望我的类能够自己创建对象,我发现这在“new”中是可能的,但显然它不起作用,因为我遇到了以下错误:

类型错误:object()不接受任何参数

这就是我正在使用的类,我会发布所有的类,以防它们来自代码的另一部分

class Planete:

    def __new__(cls, rayon, periode, envergure,look):


        print("test __new__ of the class {}".format(cls))

        return object.__new__(cls, rayon, periode, envergure,look)

    def __init__(self,rayon,periode,envergure,look):

        self.rayon = rayon
        self.periode = periode
        #self.couleur = couleur
        self.envergure = envergure
        self.omega = (2*math.pi)/self.periode
        self.i = 0

        self.look = pygame.transform.rotozoom(look,0,self.envergure)

        self.rect = pygame.Rect((0, 0), (0, 0))

        #self.surf = pygame.Surface(self.rect.size)

    def tourner(self) :

        self.x = self.rayon*math.cos(self.omega*self.i)
        self.x2 = int(self.x)+600
        self.y = self.rayon*math.sin(self.omega*self.i)
        self.y2 = int(self.y)+300
        self.i = self.i + 1

        self.rect = pygame.Rect((self.x2, self.y2), (50, 50))

    def dessiner(self):
        #pygame.draw.circle(gameDisplay,(self.couleur),((self.x2, self.y2)), self.envergure)
        #gameDisplay.blit(self.surf,self)
        gameDisplay.blit(self.look,(self.x2, self.y2))

问题正是错误消息所说的:
TypeError:object()不接受任何参数

\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

直接修复方法是将该行替换为:

    return object.__new__(cls)
但无论如何,正如您在评论中所说的,您没有真正的理由在这里使用
\uuuuu new\uuuu
:摘自Python语言参考:

new()主要用于允许不可变类型的子类(如int、str或tuple)自定义实例创建


由于您的
Planete
类不是一个不变的类型,并且当您使用
\uuuuu init\uuuuuu
进行自定义时,您根本不应该使用
\uuuu new\uuuuuuuu

当您需要控制新实例的创建时,请使用\u_;new\u
。为什么要这样做?错误信息是如何不清楚的?请编辑您的源代码,使其成为可以重现错误的完整示例。(提示:删除与PyGame相关的行,添加
import math
,添加导致
TypeError:object()不带参数的行)