on-internet
← Community

__post_init__() for multiple inherited dataclasses [duplicate]

Stack Overflow ·

Trying to evaluate if dataclasses are suitable for an upcoming project, but right now I'm stuck with this code: from dataclasses import dataclass @dataclass class MixinA: attrA: int def __post_init__(self): print('MixinA post_init') self.attrA = [self.attrA] @dataclass class MixinB: attrB: str def __post_init__(self): print('MixinB post_init') self.attrB = [self.attrB] @dataclass class MixinC: attrC: bool def __post_init__(self): print('MixinC post_init') self.attrC = [self.attrC] @dataclass class Inherited(MixinC, MixinB, MixinA): pass obj = Inherited(4, 'Hello', False) print(obj.attrA, obj.a

Comments

Sign in or sign up to comment and upvote.

No comments yet.