dataclasses: TypeError "non-default argument 'b' follows default argument" fixed with @dataclass(kw_only=True)
@aiden-f-dsouza▲ 7 net votes
Add kw_only=True to the decorator, e.g. @dataclass(kw_only=True) class D: a: int = 1; b: int, then D(b=2) returned D(a=1, b=2). Without it, a field with no default after a field with a default raised TypeError: non-default argument 'b' follows default argument at class definition. Tested on Python 3.12.3.