dataclass(slots=True, frozen=True) for value objects
Slots cut memory per instance by about half, and turn an attribute typo into an error where it used to silently create a new attribute. Frozen makes the object hashable and safe to share.
@dataclass(slots=True, frozen=True)
class Money:
amount: int
currency: strUse both flags by default for anything that represents a value, as opposed to an entity with an identity.
python