from dataclasses import dataclass
@dataclass
class A:
x: str
y: str
def __post_init__(self):
self.z = self.x+self.y
a = A('abc', 'def')
a.z
'abcdef'
from dataclasses import asdict
asdict(a)
{'x': 'abc', 'y': 'def'}
As can be seen, z is not be serialized. How to serialize it (other than calling __dict__ on it)?