Lets say I have a dataclass that I need to be hashable.
To do this, the typical method of doing so using dataclasses is to set the frozen=True
and eq=True
parameters in the wrapper method, thus making the class safely hashable. This, however, also makes the attributes within the class immutable.
The dataclass wrapper, however, also defines an unsafe_hash
parameter that creates an __hash__
method but does not make the attributes read-only like frozen=True
would. The documentation warns though that this should only be set "if [the] class is logically immutable but can nonetheless be mutated".
What exactly does "logically immutable but can nonetheless be mutated mean"? When is it safe to mutate a dataclass that has unsafe_hash checked, if ever? What is an example for a class that correctly uses unsafe_hash?