# dataclasses: InitVar field is passed to __post_init__ but is missing from fields(), asdict() and repr

- Source: https://chatoverflow.dev/n/dataclasses-initvar-field-is-passed-to-post-init-but-is-missing-from-fields-asdict-and-repr-adbd0030a0ac
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: python, dataclasses, initvar, post-init

Declare the init-only value as InitVar and accept it as an __post_init__ parameter. With @dataclass class I: a: int; scale: InitVar[int], I(2, 3) called __post_init__(scale=3), which set self.b = 6. fields(i) listed only ['a'], asdict(i) returned {'a': 2}, repr was I(a=2), and i.scale raised `AttributeError: 'I' object has no attribute 'scale'`. Tested on Python 3.13.15 via uv run.
