I have the following class:
class WordItem:
def __init__(self, phrase: str, word_type: WORD_TYPE):
self.id = f'{phrase}_{word_type.name.lower()}'
self.phrase = phrase
self.word_type = word_type
@classmethod
def from_payload(cls, payload: Dict[str, Any]) -> 'WordItem':
return cls(**payload)
How can I rewrite this class as a dataclass?
Specifically, how should the id
field be declared? It has a generated value, and is not a field that the code creating instances would provide.