massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / types.pyi
1 import sys
2 from importlib.abc import _LoaderProtocol
3 from importlib.machinery import ModuleSpec
4 from typing import (
5     Any,
6     AsyncGenerator,
7     Awaitable,
8     Callable,
9     Coroutine,
10     Generator,
11     Generic,
12     ItemsView,
13     Iterable,
14     Iterator,
15     KeysView,
16     Mapping,
17     MutableSequence,
18     Tuple,
19     Type,
20     TypeVar,
21     ValuesView,
22     overload,
23 )
24 from typing_extensions import Literal, ParamSpec, final
25
26 # Note, all classes "defined" here require special handling.
27
28 _T = TypeVar("_T")
29 _T1 = TypeVar("_T1")
30 _T2 = TypeVar("_T2")
31 _T_co = TypeVar("_T_co", covariant=True)
32 _T_contra = TypeVar("_T_contra", contravariant=True)
33 _KT = TypeVar("_KT")
34 _VT_co = TypeVar("_VT_co", covariant=True)
35 _V_co = TypeVar("_V_co", covariant=True)
36
37 @final
38 class _Cell:
39     __hash__: None  # type: ignore
40     cell_contents: Any
41
42 @final
43 class FunctionType:
44     __closure__: Tuple[_Cell, ...] | None
45     __code__: CodeType
46     __defaults__: Tuple[Any, ...] | None
47     __dict__: dict[str, Any]
48     __globals__: dict[str, Any]
49     __name__: str
50     __qualname__: str
51     __annotations__: dict[str, Any]
52     __kwdefaults__: dict[str, Any]
53     def __init__(
54         self,
55         code: CodeType,
56         globals: dict[str, Any],
57         name: str | None = ...,
58         argdefs: Tuple[object, ...] | None = ...,
59         closure: Tuple[_Cell, ...] | None = ...,
60     ) -> None: ...
61     def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
62     def __get__(self, obj: object | None, type: type | None) -> MethodType: ...
63
64 LambdaType = FunctionType
65
66 @final
67 class CodeType:
68     """Create a code object.  Not for the faint of heart."""
69
70     co_argcount: int
71     if sys.version_info >= (3, 8):
72         co_posonlyargcount: int
73     co_kwonlyargcount: int
74     co_nlocals: int
75     co_stacksize: int
76     co_flags: int
77     co_code: bytes
78     co_consts: Tuple[Any, ...]
79     co_names: Tuple[str, ...]
80     co_varnames: Tuple[str, ...]
81     co_filename: str
82     co_name: str
83     co_firstlineno: int
84     co_lnotab: bytes
85     co_freevars: Tuple[str, ...]
86     co_cellvars: Tuple[str, ...]
87     if sys.version_info >= (3, 8):
88         def __init__(
89             self,
90             argcount: int,
91             posonlyargcount: int,
92             kwonlyargcount: int,
93             nlocals: int,
94             stacksize: int,
95             flags: int,
96             codestring: bytes,
97             constants: Tuple[Any, ...],
98             names: Tuple[str, ...],
99             varnames: Tuple[str, ...],
100             filename: str,
101             name: str,
102             firstlineno: int,
103             lnotab: bytes,
104             freevars: Tuple[str, ...] = ...,
105             cellvars: Tuple[str, ...] = ...,
106         ) -> None: ...
107     else:
108         def __init__(
109             self,
110             argcount: int,
111             kwonlyargcount: int,
112             nlocals: int,
113             stacksize: int,
114             flags: int,
115             codestring: bytes,
116             constants: Tuple[Any, ...],
117             names: Tuple[str, ...],
118             varnames: Tuple[str, ...],
119             filename: str,
120             name: str,
121             firstlineno: int,
122             lnotab: bytes,
123             freevars: Tuple[str, ...] = ...,
124             cellvars: Tuple[str, ...] = ...,
125         ) -> None: ...
126     if sys.version_info >= (3, 8):
127         def replace(
128             self,
129             *,
130             co_argcount: int = ...,
131             co_posonlyargcount: int = ...,
132             co_kwonlyargcount: int = ...,
133             co_nlocals: int = ...,
134             co_stacksize: int = ...,
135             co_flags: int = ...,
136             co_firstlineno: int = ...,
137             co_code: bytes = ...,
138             co_consts: Tuple[Any, ...] = ...,
139             co_names: Tuple[str, ...] = ...,
140             co_varnames: Tuple[str, ...] = ...,
141             co_freevars: Tuple[str, ...] = ...,
142             co_cellvars: Tuple[str, ...] = ...,
143             co_filename: str = ...,
144             co_name: str = ...,
145             co_lnotab: bytes = ...,
146         ) -> CodeType: ...
147     if sys.version_info >= (3, 11):
148         def co_positions(self) -> Iterable[tuple[int | None, int | None, int | None, int | None]]: ...
149
150 @final
151 class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]):
152     __hash__: None  # type: ignore
153     def __init__(self, mapping: Mapping[_KT, _VT_co]) -> None: ...
154     def __getitem__(self, k: _KT) -> _VT_co: ...
155     def __iter__(self) -> Iterator[_KT]: ...
156     def __len__(self) -> int: ...
157     def copy(self) -> dict[_KT, _VT_co]: ...
158     def keys(self) -> KeysView[_KT]: ...
159     def values(self) -> ValuesView[_VT_co]: ...
160     def items(self) -> ItemsView[_KT, _VT_co]: ...
161     if sys.version_info >= (3, 9):
162         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
163         def __reversed__(self) -> Iterator[_KT]: ...
164         def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT_co | _T2]: ...
165         def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT_co | _T2]: ...
166
167 class SimpleNamespace:
168     __hash__: None  # type: ignore
169     def __init__(self, **kwargs: Any) -> None: ...
170     def __getattribute__(self, name: str) -> Any: ...
171     def __setattr__(self, name: str, value: Any) -> None: ...
172     def __delattr__(self, name: str) -> None: ...
173
174 class ModuleType:
175     __name__: str
176     __file__: str | None
177     __dict__: dict[str, Any]
178     __loader__: _LoaderProtocol | None
179     __package__: str | None
180     __path__: MutableSequence[str]
181     __spec__: ModuleSpec | None
182     def __init__(self, name: str, doc: str | None = ...) -> None: ...
183     # __getattr__ doesn't exist at runtime,
184     # but having it here in typeshed makes dynamic imports
185     # using `builtins.__import__` or `importlib.import_module` less painful
186     def __getattr__(self, name: str) -> Any: ...
187
188 @final
189 class GeneratorType(Generator[_T_co, _T_contra, _V_co]):
190     gi_code: CodeType
191     gi_frame: FrameType
192     gi_running: bool
193     gi_yieldfrom: GeneratorType[_T_co, _T_contra, Any] | None
194     def __iter__(self) -> GeneratorType[_T_co, _T_contra, _V_co]: ...
195     def __next__(self) -> _T_co: ...
196     def close(self) -> None: ...
197     def send(self, __arg: _T_contra) -> _T_co: ...
198     @overload
199     def throw(
200         self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
201     ) -> _T_co: ...
202     @overload
203     def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
204
205 @final
206 class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]):
207     ag_await: Awaitable[Any] | None
208     ag_frame: FrameType
209     ag_running: bool
210     ag_code: CodeType
211     def __aiter__(self) -> AsyncGeneratorType[_T_co, _T_contra]: ...
212     def __anext__(self) -> Awaitable[_T_co]: ...
213     def asend(self, __val: _T_contra) -> Awaitable[_T_co]: ...
214     @overload
215     def athrow(
216         self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
217     ) -> Awaitable[_T_co]: ...
218     @overload
219     def athrow(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> Awaitable[_T_co]: ...
220     def aclose(self) -> Awaitable[None]: ...
221
222 @final
223 class CoroutineType(Coroutine[_T_co, _T_contra, _V_co]):
224     __name__: str
225     __qualname__: str
226     cr_await: Any | None
227     cr_code: CodeType
228     cr_frame: FrameType
229     cr_running: bool
230     def close(self) -> None: ...
231     def __await__(self) -> Generator[Any, None, _V_co]: ...
232     def send(self, __arg: _T_contra) -> _T_co: ...
233     @overload
234     def throw(
235         self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
236     ) -> _T_co: ...
237     @overload
238     def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
239
240 class _StaticFunctionType:
241     """Fictional type to correct the type of MethodType.__func__.
242
243     FunctionType is a descriptor, so mypy follows the descriptor protocol and
244     converts MethodType.__func__ back to MethodType (the return type of
245     FunctionType.__get__). But this is actually a special case; MethodType is
246     implemented in C and its attribute access doesn't go through
247     __getattribute__.
248
249     By wrapping FunctionType in _StaticFunctionType, we get the right result;
250     similar to wrapping a function in staticmethod() at runtime to prevent it
251     being bound as a method.
252     """
253
254     def __get__(self, obj: object | None, type: type | None) -> FunctionType: ...
255
256 @final
257 class MethodType:
258     __closure__: Tuple[_Cell, ...] | None  # inherited from the added function
259     __defaults__: Tuple[Any, ...] | None  # inherited from the added function
260     __func__: _StaticFunctionType
261     __self__: object
262     __name__: str  # inherited from the added function
263     __qualname__: str  # inherited from the added function
264     def __init__(self, func: Callable[..., Any], obj: object) -> None: ...
265     def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
266
267 @final
268 class BuiltinFunctionType:
269     __self__: object | ModuleType
270     __name__: str
271     __qualname__: str
272     def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
273
274 BuiltinMethodType = BuiltinFunctionType
275
276 if sys.version_info >= (3, 7):
277     @final
278     class WrapperDescriptorType:
279         __name__: str
280         __qualname__: str
281         __objclass__: type
282         def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
283         def __get__(self, obj: Any, type: type = ...) -> Any: ...
284     @final
285     class MethodWrapperType:
286         __self__: object
287         __name__: str
288         __qualname__: str
289         __objclass__: type
290         def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
291         def __eq__(self, other: Any) -> bool: ...
292         def __ne__(self, other: Any) -> bool: ...
293     @final
294     class MethodDescriptorType:
295         __name__: str
296         __qualname__: str
297         __objclass__: type
298         def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
299         def __get__(self, obj: Any, type: type = ...) -> Any: ...
300     @final
301     class ClassMethodDescriptorType:
302         __name__: str
303         __qualname__: str
304         __objclass__: type
305         def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
306         def __get__(self, obj: Any, type: type = ...) -> Any: ...
307
308 @final
309 class TracebackType:
310     if sys.version_info >= (3, 7):
311         def __init__(self, tb_next: TracebackType | None, tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ...
312         tb_next: TracebackType | None
313     else:
314         @property
315         def tb_next(self) -> TracebackType | None: ...
316     # the rest are read-only even in 3.7
317     @property
318     def tb_frame(self) -> FrameType: ...
319     @property
320     def tb_lasti(self) -> int: ...
321     @property
322     def tb_lineno(self) -> int: ...
323
324 @final
325 class FrameType:
326     f_back: FrameType | None
327     f_builtins: dict[str, Any]
328     f_code: CodeType
329     f_globals: dict[str, Any]
330     f_lasti: int
331     f_lineno: int
332     f_locals: dict[str, Any]
333     f_trace: Callable[[FrameType, str, Any], Any] | None
334     if sys.version_info >= (3, 7):
335         f_trace_lines: bool
336         f_trace_opcodes: bool
337     def clear(self) -> None: ...
338
339 @final
340 class GetSetDescriptorType:
341     __name__: str
342     __objclass__: type
343     def __get__(self, __obj: Any, __type: type = ...) -> Any: ...
344     def __set__(self, __instance: Any, __value: Any) -> None: ...
345     def __delete__(self, obj: Any) -> None: ...
346
347 @final
348 class MemberDescriptorType:
349     __name__: str
350     __objclass__: type
351     def __get__(self, __obj: Any, __type: type = ...) -> Any: ...
352     def __set__(self, __instance: Any, __value: Any) -> None: ...
353     def __delete__(self, obj: Any) -> None: ...
354
355 if sys.version_info >= (3, 7):
356     def new_class(
357         name: str,
358         bases: Iterable[object] = ...,
359         kwds: dict[str, Any] | None = ...,
360         exec_body: Callable[[dict[str, Any]], None] | None = ...,
361     ) -> type: ...
362     def resolve_bases(bases: Iterable[object]) -> Tuple[Any, ...]: ...
363
364 else:
365     def new_class(
366         name: str,
367         bases: Tuple[type, ...] = ...,
368         kwds: dict[str, Any] | None = ...,
369         exec_body: Callable[[dict[str, Any]], None] | None = ...,
370     ) -> type: ...
371
372 def prepare_class(
373     name: str, bases: Tuple[type, ...] = ..., kwds: dict[str, Any] | None = ...
374 ) -> tuple[type, dict[str, Any], dict[str, Any]]: ...
375
376 # Actually a different type, but `property` is special and we want that too.
377 DynamicClassAttribute = property
378
379 _Fn = TypeVar("_Fn", bound=Callable[..., object])
380 _R = TypeVar("_R")
381 _P = ParamSpec("_P")
382
383 # it's not really an Awaitable, but can be used in an await expression. Real type: Generator & Awaitable
384 @overload
385 def coroutine(func: Callable[_P, Generator[_R, Any, Any]]) -> Callable[_P, Awaitable[_R]]: ...  # type: ignore
386 @overload
387 def coroutine(func: _Fn) -> _Fn: ...  # type: ignore
388
389 if sys.version_info >= (3, 8):
390     CellType = _Cell
391
392 if sys.version_info >= (3, 9):
393     class GenericAlias:
394         __origin__: type
395         __args__: Tuple[Any, ...]
396         __parameters__: Tuple[Any, ...]
397         def __init__(self, origin: type, args: Any) -> None: ...
398         def __getattr__(self, name: str) -> Any: ...  # incomplete
399
400 if sys.version_info >= (3, 10):
401     @final
402     class NoneType:
403         def __bool__(self) -> Literal[False]: ...
404     EllipsisType = ellipsis  # noqa F811 from builtins
405     from builtins import _NotImplementedType
406
407     NotImplementedType = _NotImplementedType  # noqa F811 from builtins
408     @final
409     class UnionType:
410         __args__: Tuple[Any, ...]
411         def __or__(self, obj: Any) -> UnionType: ...
412         def __ror__(self, obj: Any) -> UnionType: ...