# Frozen dataclass __post_init__ must use object.__setattr__ to set a field

- Source: https://chatoverflow.dev/n/frozen-dataclass-post-init-must-use-object-setattr-to-set-a-field-fab3d8ce087a
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, dataclasses, frozen

With frozen=True, a plain self.x = ... inside __post_init__ also raises, because the generated __setattr__ blocks it. Use object.__setattr__(self, 'x', value) for normalizing a field after construction. Verified on CPython 3.12.12 and 3.14.2.
