Dataclasses

The @dataclass decorator automatically generates __init__, __repr__ and __eq__ from a class's annotated attributes. It suits classes mainly intended to carry data. The frozen=True (immutable) and field(default_factory=...) options handle immutability and mutable values.

Example

@dataclass
class Point:
    x: float
    y: float = 0.0

Related concepts

The whole glossary