massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / _typeshed / __init__.pyi
1 # Utility types for typeshed
2 #
3 # See the README.md file in this directory for more information.
4
5 import array
6 import ctypes
7 import mmap
8 import sys
9 from os import PathLike
10 from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, TypeVar, Union
11 from typing_extensions import Literal, final
12
13 _KT = TypeVar("_KT")
14 _KT_co = TypeVar("_KT_co", covariant=True)
15 _KT_contra = TypeVar("_KT_contra", contravariant=True)
16 _VT = TypeVar("_VT")
17 _VT_co = TypeVar("_VT_co", covariant=True)
18 _T = TypeVar("_T")
19 _T_co = TypeVar("_T_co", covariant=True)
20 _T_contra = TypeVar("_T_contra", contravariant=True)
21
22 # Use for "self" annotations:
23 #   def __enter__(self: Self) -> Self: ...
24 Self = TypeVar("Self")  # noqa Y001
25
26 # stable
27 class IdentityFunction(Protocol):
28     def __call__(self, __x: _T) -> _T: ...
29
30 # stable
31 class SupportsNext(Protocol[_T_co]):
32     def __next__(self) -> _T_co: ...
33
34 # stable
35 class SupportsAnext(Protocol[_T_co]):
36     def __anext__(self) -> Awaitable[_T_co]: ...
37
38 class SupportsLessThan(Protocol):
39     def __lt__(self, __other: Any) -> bool: ...
40
41 SupportsLessThanT = TypeVar("SupportsLessThanT", bound=SupportsLessThan)  # noqa: Y001
42
43 class SupportsGreaterThan(Protocol):
44     def __gt__(self, __other: Any) -> bool: ...
45
46 SupportsGreaterThanT = TypeVar("SupportsGreaterThanT", bound=SupportsGreaterThan)  # noqa: Y001
47
48 class SupportsDivMod(Protocol[_T_contra, _T_co]):
49     def __divmod__(self, __other: _T_contra) -> _T_co: ...
50
51 class SupportsRDivMod(Protocol[_T_contra, _T_co]):
52     def __rdivmod__(self, __other: _T_contra) -> _T_co: ...
53
54 class SupportsLenAndGetItem(Protocol[_T_co]):
55     def __len__(self) -> int: ...
56     def __getitem__(self, __k: int) -> _T_co: ...
57
58 class SupportsTrunc(Protocol):
59     def __trunc__(self) -> int: ...
60
61 # Mapping-like protocols
62
63 # stable
64 class SupportsItems(Protocol[_KT_co, _VT_co]):
65     def items(self) -> AbstractSet[tuple[_KT_co, _VT_co]]: ...
66
67 # stable
68 class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
69     def keys(self) -> Iterable[_KT]: ...
70     def __getitem__(self, __k: _KT) -> _VT_co: ...
71
72 # stable
73 class SupportsGetItem(Container[_KT_contra], Protocol[_KT_contra, _VT_co]):
74     def __getitem__(self, __k: _KT_contra) -> _VT_co: ...
75
76 # stable
77 class SupportsItemAccess(SupportsGetItem[_KT_contra, _VT], Protocol[_KT_contra, _VT]):
78     def __setitem__(self, __k: _KT_contra, __v: _VT) -> None: ...
79     def __delitem__(self, __v: _KT_contra) -> None: ...
80
81 # These aliases are simple strings in Python 2.
82 StrPath = Union[str, PathLike[str]]  # stable
83 BytesPath = Union[bytes, PathLike[bytes]]  # stable
84 StrOrBytesPath = Union[str, bytes, PathLike[str], PathLike[bytes]]  # stable
85
86 OpenTextModeUpdating = Literal[
87     "r+",
88     "+r",
89     "rt+",
90     "r+t",
91     "+rt",
92     "tr+",
93     "t+r",
94     "+tr",
95     "w+",
96     "+w",
97     "wt+",
98     "w+t",
99     "+wt",
100     "tw+",
101     "t+w",
102     "+tw",
103     "a+",
104     "+a",
105     "at+",
106     "a+t",
107     "+at",
108     "ta+",
109     "t+a",
110     "+ta",
111     "x+",
112     "+x",
113     "xt+",
114     "x+t",
115     "+xt",
116     "tx+",
117     "t+x",
118     "+tx",
119 ]
120 OpenTextModeWriting = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"]
121 OpenTextModeReading = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"]
122 OpenTextMode = Union[OpenTextModeUpdating, OpenTextModeWriting, OpenTextModeReading]
123 OpenBinaryModeUpdating = Literal[
124     "rb+",
125     "r+b",
126     "+rb",
127     "br+",
128     "b+r",
129     "+br",
130     "wb+",
131     "w+b",
132     "+wb",
133     "bw+",
134     "b+w",
135     "+bw",
136     "ab+",
137     "a+b",
138     "+ab",
139     "ba+",
140     "b+a",
141     "+ba",
142     "xb+",
143     "x+b",
144     "+xb",
145     "bx+",
146     "b+x",
147     "+bx",
148 ]
149 OpenBinaryModeWriting = Literal["wb", "bw", "ab", "ba", "xb", "bx"]
150 OpenBinaryModeReading = Literal["rb", "br", "rbU", "rUb", "Urb", "brU", "bUr", "Ubr"]
151 OpenBinaryMode = Union[OpenBinaryModeUpdating, OpenBinaryModeReading, OpenBinaryModeWriting]
152
153 # stable
154 class HasFileno(Protocol):
155     def fileno(self) -> int: ...
156
157 FileDescriptor = int  # stable
158 FileDescriptorLike = Union[int, HasFileno]  # stable
159
160 # stable
161 class SupportsRead(Protocol[_T_co]):
162     def read(self, __length: int = ...) -> _T_co: ...
163
164 # stable
165 class SupportsReadline(Protocol[_T_co]):
166     def readline(self, __length: int = ...) -> _T_co: ...
167
168 # stable
169 class SupportsNoArgReadline(Protocol[_T_co]):
170     def readline(self) -> _T_co: ...
171
172 # stable
173 class SupportsWrite(Protocol[_T_contra]):
174     def write(self, __s: _T_contra) -> Any: ...
175
176 ReadOnlyBuffer = bytes  # stable
177 # Anything that implements the read-write buffer interface.
178 # The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
179 # for it. Instead we have to list the most common stdlib buffer classes in a Union.
180 WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, ctypes._CData]  # stable
181 # Same as _WriteableBuffer, but also includes read-only buffer types (like bytes).
182 ReadableBuffer = Union[ReadOnlyBuffer, WriteableBuffer]  # stable
183
184 # stable
185 if sys.version_info >= (3, 10):
186     from types import NoneType as NoneType
187 else:
188     # Used by type checkers for checks involving None (does not exist at runtime)
189     @final
190     class NoneType:
191         def __bool__(self) -> Literal[False]: ...