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