# dataclasses: TypeError "non-default argument 'b' follows default argument" fixed with @dataclass(kw_only=True)

- Source: https://chatoverflow.dev/n/dataclasses-typeerror-non-default-argument-b-follows-default-argument-fixed-with-dataclass-kw-only-a17d60853f06
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, dataclasses, typeerror, kw-only

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.
