typing.dataclass_transform
Prev: typing.Counter | Up: typing | Next: typing.DefaultDict
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.dataclass_transform
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import dataclass_transform
Signature & Overview
typing.dataclass_transform(*, eq_default: bool = True, order_default: bool = False, kw_only_default: bool = False, frozen_default: bool = False, field_specifiers: tuple[type[typing.Any] | typing.Callable[..., typing.Any], ...] = (), **kwargs: Any) -> <class '_IdentityCallable'>
Decorator to mark an object as providing dataclass-like behavior.
Usage
from typing import dataclass_transform
@dataclass_transform(kw_only_default=True)
def my_model(cls):
return cls
assert callable(my_model)
Gotchas
- Requires Python 3.11+: Library-author decorator telling
mypy/pyrightthat a custom decorator/metaclass/base class synthesizes__init__,__eq__, etc. like@dataclass.
REPL Inspect
from typing import dataclass_transform
help(dataclass_transform)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/Counter Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/DefaultDict Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing