massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / dataclasses.pyi
1 import sys
2 import types
3 from typing import Any, Callable, Generic, Iterable, Mapping, Tuple, Type, TypeVar, overload
4 from typing_extensions import Protocol
5
6 if sys.version_info >= (3, 9):
7     from types import GenericAlias
8
9 _T = TypeVar("_T")
10 _T_co = TypeVar("_T_co", covariant=True)
11
12 class _MISSING_TYPE: ...
13
14 MISSING: _MISSING_TYPE
15
16 if sys.version_info >= (3, 10):
17     class KW_ONLY: ...
18
19 @overload
20 def asdict(obj: Any) -> dict[str, Any]: ...
21 @overload
22 def asdict(obj: Any, *, dict_factory: Callable[[list[tuple[str, Any]]], _T]) -> _T: ...
23 @overload
24 def astuple(obj: Any) -> Tuple[Any, ...]: ...
25 @overload
26 def astuple(obj: Any, *, tuple_factory: Callable[[list[Any]], _T]) -> _T: ...
27
28 if sys.version_info >= (3, 10):
29     @overload
30     def dataclass(__cls: Type[_T]) -> Type[_T]: ...
31     @overload
32     def dataclass(__cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
33     @overload
34     def dataclass(
35         *,
36         init: bool = ...,
37         repr: bool = ...,
38         eq: bool = ...,
39         order: bool = ...,
40         unsafe_hash: bool = ...,
41         frozen: bool = ...,
42         match_args: bool = ...,
43         kw_only: bool = ...,
44         slots: bool = ...,
45     ) -> Callable[[Type[_T]], Type[_T]]: ...
46
47 elif sys.version_info >= (3, 8):
48     # cls argument is now positional-only
49     @overload
50     def dataclass(__cls: Type[_T]) -> Type[_T]: ...
51     @overload
52     def dataclass(__cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
53     @overload
54     def dataclass(
55         *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
56     ) -> Callable[[Type[_T]], Type[_T]]: ...
57
58 else:
59     @overload
60     def dataclass(_cls: Type[_T]) -> Type[_T]: ...
61     @overload
62     def dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
63     @overload
64     def dataclass(
65         *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
66     ) -> Callable[[Type[_T]], Type[_T]]: ...
67
68 # See https://github.com/python/mypy/issues/10750
69 class _DefaultFactory(Protocol[_T_co]):
70     def __call__(self) -> _T_co: ...
71
72 class Field(Generic[_T]):
73     name: str
74     type: Type[_T]
75     default: _T
76     default_factory: _DefaultFactory[_T]
77     repr: bool
78     hash: bool | None
79     init: bool
80     compare: bool
81     metadata: types.MappingProxyType[Any, Any]
82     if sys.version_info >= (3, 10):
83         kw_only: bool
84         def __init__(
85             self,
86             default: _T,
87             default_factory: Callable[[], _T],
88             init: bool,
89             repr: bool,
90             hash: bool | None,
91             compare: bool,
92             metadata: Mapping[Any, Any],
93             kw_only: bool,
94         ) -> None: ...
95     else:
96         def __init__(
97             self,
98             default: _T,
99             default_factory: Callable[[], _T],
100             init: bool,
101             repr: bool,
102             hash: bool | None,
103             compare: bool,
104             metadata: Mapping[Any, Any],
105         ) -> None: ...
106     if sys.version_info >= (3, 9):
107         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
108
109 # NOTE: Actual return type is 'Field[_T]', but we want to help type checkers
110 # to understand the magic that happens at runtime.
111 if sys.version_info >= (3, 10):
112     @overload  # `default` and `default_factory` are optional and mutually exclusive.
113     def field(
114         *,
115         default: _T,
116         init: bool = ...,
117         repr: bool = ...,
118         hash: bool | None = ...,
119         compare: bool = ...,
120         metadata: Mapping[Any, Any] | None = ...,
121         kw_only: bool = ...,
122     ) -> _T: ...
123     @overload
124     def field(
125         *,
126         default_factory: Callable[[], _T],
127         init: bool = ...,
128         repr: bool = ...,
129         hash: bool | None = ...,
130         compare: bool = ...,
131         metadata: Mapping[Any, Any] | None = ...,
132         kw_only: bool = ...,
133     ) -> _T: ...
134     @overload
135     def field(
136         *,
137         init: bool = ...,
138         repr: bool = ...,
139         hash: bool | None = ...,
140         compare: bool = ...,
141         metadata: Mapping[Any, Any] | None = ...,
142         kw_only: bool = ...,
143     ) -> Any: ...
144
145 else:
146     @overload  # `default` and `default_factory` are optional and mutually exclusive.
147     def field(
148         *,
149         default: _T,
150         init: bool = ...,
151         repr: bool = ...,
152         hash: bool | None = ...,
153         compare: bool = ...,
154         metadata: Mapping[Any, Any] | None = ...,
155     ) -> _T: ...
156     @overload
157     def field(
158         *,
159         default_factory: Callable[[], _T],
160         init: bool = ...,
161         repr: bool = ...,
162         hash: bool | None = ...,
163         compare: bool = ...,
164         metadata: Mapping[Any, Any] | None = ...,
165     ) -> _T: ...
166     @overload
167     def field(
168         *,
169         init: bool = ...,
170         repr: bool = ...,
171         hash: bool | None = ...,
172         compare: bool = ...,
173         metadata: Mapping[Any, Any] | None = ...,
174     ) -> Any: ...
175
176 def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ...
177 def is_dataclass(obj: Any) -> bool: ...
178
179 class FrozenInstanceError(AttributeError): ...
180
181 class InitVar(Generic[_T]):
182     type: Type[_T]
183     def __init__(self, type: Type[_T]) -> None: ...
184     if sys.version_info >= (3, 9):
185         @overload
186         def __class_getitem__(cls, type: Type[_T]) -> InitVar[_T]: ...
187         @overload
188         def __class_getitem__(cls, type: Any) -> InitVar[Any]: ...
189
190 if sys.version_info >= (3, 10):
191     def make_dataclass(
192         cls_name: str,
193         fields: Iterable[str | tuple[str, type] | tuple[str, type, Field[Any]]],
194         *,
195         bases: Tuple[type, ...] = ...,
196         namespace: dict[str, Any] | None = ...,
197         init: bool = ...,
198         repr: bool = ...,
199         eq: bool = ...,
200         order: bool = ...,
201         unsafe_hash: bool = ...,
202         frozen: bool = ...,
203         match_args: bool = ...,
204         slots: bool = ...,
205     ) -> type: ...
206
207 else:
208     def make_dataclass(
209         cls_name: str,
210         fields: Iterable[str | tuple[str, type] | tuple[str, type, Field[Any]]],
211         *,
212         bases: Tuple[type, ...] = ...,
213         namespace: dict[str, Any] | None = ...,
214         init: bool = ...,
215         repr: bool = ...,
216         eq: bool = ...,
217         order: bool = ...,
218         unsafe_hash: bool = ...,
219         frozen: bool = ...,
220     ) -> type: ...
221
222 def replace(__obj: _T, **changes: Any) -> _T: ...