The following will work, but I'd rather not need to repeat the __hash__ in each subclass. Is there a way to tell the dataclass to inherit the hash function (i.e. not set it to None)?
from dataclasses import dataclass
@dataclass
class Hashable:
def __hash__(self):
hashed = hash((
getattr(self, key)
for key in self.__annotations__
))
return hashed
@dataclass
class Node(Hashable):
name: str = 'Undefined'
def __hash__(self):
return Hashable.__hash__(self)