dataclass(slots=True, frozen=True) for value objects
Slots cut memory per instance by around half and make attribute typos an error instead of a silent new attribute. Frozen makes the object hashable and safe to share.
@dataclass(slots=True, frozen=True)
class Money:
amount: int
currency: strFor anything that represents a value rather than an entity with identity, both flags, by default.
python