我想放置__slots__一个带有默认字段的数据类。当我尝试这样做时,我收到此错误:
>>> @dataclass
... class C:
... __slots__ = ('x', 'y', )
... x: int
... y: int = 1
...
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: 'y' in __slots__ conflicts with class variable
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这一目标?