dataclass
A decorator introduced in Python 3.7 that automatically generates basic class methods such as __init__ and __repr__, simplifying the definition of data classes. By default all fields are public and there is no enforcement of business rules, so it must be used with care for domain objects.
Timeline (last 90 days)
Every field of a dataclass is public by default and does not enforce any business constraints, so callers can pass in business-illegal values (such as discount=2.0).
When an object needs to guard business rules, a regular class should be used instead, providing methods that enforce the constraints, rather than using a dataclass.
A dataclass's slots=True can optimize memory usage, at the cost of no longer being able to add attributes dynamically, because there is no longer an editable __dict__.
The script separates decision logic from network IO, using pure functions plus data classes, so that branch behavior can be repeatedly verified locally with fixed inputs, unaffected by network jitter and real quotas.
When implementing snapshots in Python, a dataclass with frozen=True can be used to represent an immutable Memento object, and tuples rather than lists can be used to store mutable collections to ensure immutability.
All Facts (5)
Every field of a dataclass is public by default and does not enforce any business constraints, so callers can pass in business-illegal values (such as discount=2.0).
50%UnverifiedWhen an object needs to guard business rules, a regular class should be used instead, providing methods that enforce the constraints, rather than using a dataclass.
50%UnverifiedA dataclass's slots=True can optimize memory usage, at the cost of no longer being able to add attributes dynamically, because there is no longer an editable __dict__.
50%UnverifiedThe script separates decision logic from network IO, using pure functions plus data classes, so that branch behavior can be repeatedly verified locally with fixed inputs, unaffected by network jitter and real quotas.
50%UnverifiedWhen implementing snapshots in Python, a dataclass with frozen=True can be used to represent an immutable Memento object, and tuples rather than lists can be used to store mutable collections to ensure immutability.
50%