fromdataclassesimportdataclass@dataclass(slots=True)classBase:
def__post_init__(self):
pass@dataclass(slots=True)classThing(Base):
a: intb: intc: int=0def__post_init__(self):
self.c=self.a+self.bsuper().__post_init__()
t=Thing(1,3)
Traceback (most recent call last):
File "C:\Users\michael.foord\Code\one-touch-switch-service\example.py", line 18, in <module>
t = Thing(1,3)
^^^^^^^^^^
File "<string>", line 6, in __init__
File "C:\Users\michael.foord\Code\one-touch-switch-service\example.py", line 16, in __post_init__
super().__post_init__()
^^^^^^^
TypeError: super(type, obj): obj must be an instance or subtype of type
Bug report
Bug description:
Using
super()in__post_init__on a dataclass with slots fails.This code:
Produces this exception:
The fix is to use Python 2 style
super(Class, self).__post_init__().CPython versions tested on:
3.11
Operating systems tested on:
Windows
Linked PRs
super()without args calls fordataclasseswith slots #111538