Is it possible to specify that a single field is frozen in a non-frozen dataclass? Something like this:
@dataclass
class Data:
fixed: int = field(frozen=True)
mutable: int = field(frozen=False)
d = Data(2, 3)
d.mutable = 5 # fine
d.fixed = 7 # raises exception
I realize this can be done manually with properties and setters accessing a private data field, but then we lose some of the advantages of dataclasses: for one, the private data field needs a different name, which means the auto-generated constructor annoyingly has different parameter names than the fields.
dataclasses
does not support this, butattrs
(the project from which dataclasses was lifted) does: see attrs.org/en/stable/api.html#attr.setters.NO_OP – Lymphangitis