dataclasses to have a way to make hashable fields immutable

currently in a `dataclasses.dataclass` based class, you can either have it hashable and completely immutable (using frozen=True and eq=True), or you can have it hashable but completely mutable (by using unsafe_hash=True) unsafe_hash provides the convenience of being able to mutate some fields, while computing your hash by other, non-mutable fields. But there is nothing enforcing the fact that the fields marked with `hash=True` should stay immutable, otherwise it completely breaks hashability. The suggestion is, for the dataclass to throw an error if you try to mutate a field that contributes to the hash of that dataclass. Or, to have a flag that allows you to do so. Suggestions for the flag name could be @dataclass(freeze_hashable_fields=True) class A: ... or @dataclass(frozen_hash=True) class A: ...
participants (1)
-
Tushar Sadhwani