Given the definition of a dataclass, Name
:
@dataclass
Class Name:
user: str
I need to be able to hash an instance of Name
to use as a key in a dictionary. As it’s currently defined, and according to my understanding, it’s not possible without the frozen=True
attribute, or a given __hash__
function.
Is it possible to provide Name
with a hash function after it’s instantiation? However hackish it may be. Changing the definition of Name
is not an option. Wrapping Name
in another immutable class is not an option.
I have tried __setattr__("frozen", True)
and Name(user="").__hash__ = ...
, both do not seem to work.