2 from typing import Any, Callable, Generic, Iterable, Mapping, Tuple, Type, TypeVar, overload
4 if sys.version_info >= (3, 9):
5 from types import GenericAlias
9 class _MISSING_TYPE: ...
11 MISSING: _MISSING_TYPE
14 def asdict(obj: Any) -> dict[str, Any]: ...
16 def asdict(obj: Any, *, dict_factory: Callable[[list[tuple[str, Any]]], _T]) -> _T: ...
18 def astuple(obj: Any) -> Tuple[Any, ...]: ...
20 def astuple(obj: Any, *, tuple_factory: Callable[[list[Any]], _T]) -> _T: ...
22 def dataclass(_cls: Type[_T]) -> Type[_T]: ...
24 def dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
27 *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
28 ) -> Callable[[Type[_T]], Type[_T]]: ...
30 class Field(Generic[_T]):
34 default_factory: Callable[[], _T]
39 metadata: Mapping[str, Any]
40 if sys.version_info >= (3, 9):
41 def __class_getitem__(cls, item: Any) -> GenericAlias: ...
43 # NOTE: Actual return type is 'Field[_T]', but we want to help type checkers
44 # to understand the magic that happens at runtime.
45 @overload # `default` and `default_factory` are optional and mutually exclusive.
51 hash: bool | None = ...,
53 metadata: Mapping[str, Any] | None = ...,
58 default_factory: Callable[[], _T],
61 hash: bool | None = ...,
63 metadata: Mapping[str, Any] | None = ...,
67 *, init: bool = ..., repr: bool = ..., hash: bool | None = ..., compare: bool = ..., metadata: Mapping[str, Any] | None = ...
69 def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ...
70 def is_dataclass(obj: Any) -> bool: ...
72 class FrozenInstanceError(AttributeError): ...
74 class InitVar(Generic[_T]):
75 if sys.version_info >= (3, 9):
76 def __class_getitem__(cls, type: Any) -> GenericAlias: ...
80 fields: Iterable[str | tuple[str, type] | tuple[str, type, Field[Any]]],
82 bases: Tuple[type, ...] = ...,
83 namespace: dict[str, Any] | None = ...,
88 unsafe_hash: bool = ...,
91 def replace(obj: _T, **changes: Any) -> _T: ...