[KongchangAI]
Concept

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)

Oct 16

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).

Unverified50%
Oct 16

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.

Unverified50%
Oct 16

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__.

Unverified50%
Oct 13

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.

Unverified50%
Oct 9

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.

Unverified50%

All Facts (5)

Source Articles