Skip to main content

dataclass

No overview available.

def dataclass(
init: Literal[False] = False,
repr: bool = True,
eq: bool = True,
order: bool = False,
unsafe_hash: bool = False,
frozen: bool = False,
config: ConfigDict | type[object] | None = None,
validate_on_init: bool | None = None,
kw_only: bool = ...,
slots: bool = ...
) - > Callable[[type[_T]], type[PydanticDataclass]]

A decorator that transforms a class into a Pydantic-validated dataclass, providing automatic data validation and schema generation.

Parameters

NameTypeDescription
initLiteral[False] = FalseWhether to generate an init method; if False, the class must provide its own.
reprbool = TrueWhether to generate a repr method for the class.
eqbool = TrueWhether to generate an eq method for equality comparisons.
orderbool = FalseWhether to generate comparison methods (lt, le, gt, ge) for sorting.
unsafe_hashbool = FalseWhether to force the generation of a hash method even if the class is mutable.
frozenbool = FalseWhether to make instances immutable after initialization.
config`ConfigDicttype[object]
validate_on_init`boolNone` = None
kw_onlybool = ...Whether all fields should be marked as keyword-only in the generated init.
slotsbool = ...Whether to use slots to reduce memory footprint and prevent dynamic attribute creation.

Returns

TypeDescription
Callable[[type[_T]], type[PydanticDataclass]]A decorator function that takes a class and returns a Pydantic-enhanced version of that class.