Currently I have something like this:
@dataclass(frozen=True)
class MyClass:a: strb: strc: strd: Dict[str, str]
...which is all well and good except dict
s are mutable, so I can't use my class to key another dictionary.
Instead, I'd like field d
to be something like a FrozenSet[Tuple[str, str]]
, but I'd still like someone constructing an instance of my class to be able to pass a dictionary on the constructor as this is much more intuitive.
So I'd like to do something like
@dataclass(frozen=True)
class MyClass:a: strb: strc: strd: FrozenSet[Tuple[str, str]] = field(init=False)def __init__(self, a, b, c, d: Dict[str, str]):self.original_generated_init(a, b, c) # ???object.setattr(self, 'd', frozenset(d.items())) # required because my dataclass is frozen
How do I achieve this? Alternatively is there a more elegant way to achieve the same thing?