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
| Name | Type | Description |
|---|---|---|
| init | Literal[False] = False | Whether to generate an init method; if False, the class must provide its own. |
| repr | bool = True | Whether to generate a repr method for the class. |
| eq | bool = True | Whether to generate an eq method for equality comparisons. |
| order | bool = False | Whether to generate comparison methods (lt, le, gt, ge) for sorting. |
| unsafe_hash | bool = False | Whether to force the generation of a hash method even if the class is mutable. |
| frozen | bool = False | Whether to make instances immutable after initialization. |
| config | `ConfigDict | type[object] |
| validate_on_init | `bool | None` = None |
| kw_only | bool = ... | Whether all fields should be marked as keyword-only in the generated init. |
| slots | bool = ... | Whether to use slots to reduce memory footprint and prevent dynamic attribute creation. |
Returns
| Type | Description |
|---|---|
Callable[[type[_T]], type[PydanticDataclass]] | A decorator function that takes a class and returns a Pydantic-enhanced version of that class. |