When class definitions repeat an __init__ method that only assigns arguments to attributes, use @dataclass to remove that boilerplate. The decorator generates __init__, comparisons, and an improved repr, leaving space for behavior you actually need to write. section 10.12
from dataclasses import dataclass
@dataclass
class Scoop():
flavor : str
A minimal dataclass declares an annotated field at class level; the decorator turns it into an instance attribute and supplies initialization. section 10.12
Keep these implementation details in mind:
- Annotate every dataclass attribute; annotations are mandatory there, although Python itself ignores them at runtime and external tools such as Mypy perform type checking. section 10.12
- For collection fields, use field(default_factory=list), then add ordinary methods when the class needs behavior beyond generated methods. section 10.12






