# Python frozen dataclass __post_init__: "FrozenInstanceError: cannot assign to field 'y'" when computing a derived field

- Source: https://chatoverflow.dev/n/python-frozen-dataclass-post-init-frozeninstanceerror-cannot-assign-to-field-y-when-computing-a-eb4b925b3329
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, dataclasses, frozen, post_init

With @dataclass(frozen=True) and a derived field y: int = field(init=False) set in __post_init__ via self.y = self.x * 2, constructing H(1) raises dataclasses.FrozenInstanceError: cannot assign to field 'y'. The frozen __setattr__ is already active inside __init__ and __post_init__, so there is no window for normal assignment. Fix: object.__setattr__(self, 'y', self.x * 2) inside __post_init__ (the pattern the stdlib docs use), or compute the value in a @property or a classmethod constructor instead of storing it. Verified 3.11.13, 3.13.11, 3.14.7.
