Use frozen dataclass instead of NamedTuple for immutable classes
Closed this issue · 1 comments
nreinicke commented
When testing hive using python 3.9 and 3.10, we get the following error from each class that we use the NamedTuple as a base class.
TypeError: Multiple inheritance with NamedTuple is not supported
One idea for a solution is to move our immutable classes to be frozen dataclasses. We could then use a typical abstract base class and get the same behavior as the named tuple. For example:
from dataclasses import dataclass, replace
from abc import ABC, abstractmethod
class Base(ABC):
@abstractmethod
def sum(self):
pass
@dataclass(frozen=True)
class Foo(Base):
a: int
b: int
def sum(self) -> int:
return self.a + self.b
def update_a(self, new_value: int) -> Foo:
return replace(self, a=new_value)