massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stubs / dataclasses / dataclasses.pyi
1 import sys
2 from typing import Any, Callable, Generic, Iterable, Mapping, Tuple, Type, TypeVar, overload
3
4 if sys.version_info >= (3, 9):
5     from types import GenericAlias
6
7 _T = TypeVar("_T")
8
9 class _MISSING_TYPE: ...
10
11 MISSING: _MISSING_TYPE
12
13 @overload
14 def asdict(obj: Any) -> dict[str, Any]: ...
15 @overload
16 def asdict(obj: Any, *, dict_factory: Callable[[list[tuple[str, Any]]], _T]) -> _T: ...
17 @overload
18 def astuple(obj: Any) -> Tuple[Any, ...]: ...
19 @overload
20 def astuple(obj: Any, *, tuple_factory: Callable[[list[Any]], _T]) -> _T: ...
21 @overload
22 def dataclass(_cls: Type[_T]) -> Type[_T]: ...
23 @overload
24 def dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
25 @overload
26 def dataclass(
27     *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
28 ) -> Callable[[Type[_T]], Type[_T]]: ...
29
30 class Field(Generic[_T]):
31     name: str
32     type: Type[_T]
33     default: _T
34     default_factory: Callable[[], _T]
35     repr: bool
36     hash: bool | None
37     init: bool
38     compare: bool
39     metadata: Mapping[str, Any]
40     if sys.version_info >= (3, 9):
41         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
42
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.
46 def field(
47     *,
48     default: _T,
49     init: bool = ...,
50     repr: bool = ...,
51     hash: bool | None = ...,
52     compare: bool = ...,
53     metadata: Mapping[str, Any] | None = ...,
54 ) -> _T: ...
55 @overload
56 def field(
57     *,
58     default_factory: Callable[[], _T],
59     init: bool = ...,
60     repr: bool = ...,
61     hash: bool | None = ...,
62     compare: bool = ...,
63     metadata: Mapping[str, Any] | None = ...,
64 ) -> _T: ...
65 @overload
66 def field(
67     *, init: bool = ..., repr: bool = ..., hash: bool | None = ..., compare: bool = ..., metadata: Mapping[str, Any] | None = ...
68 ) -> Any: ...
69 def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ...
70 def is_dataclass(obj: Any) -> bool: ...
71
72 class FrozenInstanceError(AttributeError): ...
73
74 class InitVar(Generic[_T]):
75     if sys.version_info >= (3, 9):
76         def __class_getitem__(cls, type: Any) -> GenericAlias: ...
77
78 def make_dataclass(
79     cls_name: str,
80     fields: Iterable[str | tuple[str, type] | tuple[str, type, Field[Any]]],
81     *,
82     bases: Tuple[type, ...] = ...,
83     namespace: dict[str, Any] | None = ...,
84     init: bool = ...,
85     repr: bool = ...,
86     eq: bool = ...,
87     order: bool = ...,
88     unsafe_hash: bool = ...,
89     frozen: bool = ...,
90 ) -> type: ...
91 def replace(obj: _T, **changes: Any) -> _T: ...