massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / inspect.pyi
1 import enum
2 import sys
3 import types
4 from _typeshed import Self
5 from collections import OrderedDict
6 from collections.abc import Awaitable, Callable, Generator, Mapping, Sequence
7 from types import (
8     AsyncGeneratorType,
9     BuiltinFunctionType,
10     BuiltinMethodType,
11     CodeType,
12     CoroutineType,
13     FrameType,
14     FunctionType,
15     GeneratorType,
16     GetSetDescriptorType,
17     LambdaType,
18     MethodType,
19     ModuleType,
20     TracebackType,
21 )
22
23 if sys.version_info >= (3, 7):
24     from types import ClassMethodDescriptorType, WrapperDescriptorType, MemberDescriptorType, MethodDescriptorType
25
26 from typing import Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, Union
27 from typing_extensions import Literal, TypeGuard
28
29 #
30 # Types and members
31 #
32 class EndOfBlock(Exception): ...
33
34 class BlockFinder:
35     indent: int
36     islambda: bool
37     started: bool
38     passline: bool
39     indecorator: bool
40     decoratorhasargs: bool
41     last: int
42     def tokeneater(self, type: int, token: str, srowcol: tuple[int, int], erowcol: tuple[int, int], line: str) -> None: ...
43
44 CO_OPTIMIZED: int
45 CO_NEWLOCALS: int
46 CO_VARARGS: int
47 CO_VARKEYWORDS: int
48 CO_NESTED: int
49 CO_GENERATOR: int
50 CO_NOFREE: int
51 CO_COROUTINE: int
52 CO_ITERABLE_COROUTINE: int
53 CO_ASYNC_GENERATOR: int
54 TPFLAGS_IS_ABSTRACT: int
55
56 def getmembers(object: object, predicate: Callable[[Any], bool] | None = ...) -> list[tuple[str, Any]]: ...
57 def getmodulename(path: str) -> str | None: ...
58 def ismodule(object: object) -> TypeGuard[ModuleType]: ...
59 def isclass(object: object) -> TypeGuard[Type[Any]]: ...
60 def ismethod(object: object) -> TypeGuard[MethodType]: ...
61 def isfunction(object: object) -> TypeGuard[FunctionType]: ...
62
63 if sys.version_info >= (3, 8):
64     def isgeneratorfunction(obj: object) -> bool: ...
65     def iscoroutinefunction(obj: object) -> bool: ...
66
67 else:
68     def isgeneratorfunction(object: object) -> bool: ...
69     def iscoroutinefunction(object: object) -> bool: ...
70
71 def isgenerator(object: object) -> TypeGuard[GeneratorType[Any, Any, Any]]: ...
72 def iscoroutine(object: object) -> TypeGuard[CoroutineType[Any, Any, Any]]: ...
73 def isawaitable(object: object) -> TypeGuard[Awaitable[Any]]: ...
74
75 if sys.version_info >= (3, 8):
76     def isasyncgenfunction(obj: object) -> bool: ...
77
78 else:
79     def isasyncgenfunction(object: object) -> bool: ...
80
81 _T_cont = TypeVar("_T_cont", contravariant=True)
82 _V_cont = TypeVar("_V_cont", contravariant=True)
83
84 class _SupportsSet(Protocol[_T_cont, _V_cont]):
85     def __set__(self, __instance: _T_cont, __value: _V_cont) -> None: ...
86
87 class _SupportsDelete(Protocol[_T_cont]):
88     def __delete__(self, __instance: _T_cont) -> None: ...
89
90 def isasyncgen(object: object) -> TypeGuard[AsyncGeneratorType[Any, Any]]: ...
91 def istraceback(object: object) -> TypeGuard[TracebackType]: ...
92 def isframe(object: object) -> TypeGuard[FrameType]: ...
93 def iscode(object: object) -> TypeGuard[CodeType]: ...
94 def isbuiltin(object: object) -> TypeGuard[BuiltinFunctionType]: ...
95
96 if sys.version_info < (3, 7):
97     def isroutine(
98         object: object,
99     ) -> TypeGuard[FunctionType | LambdaType | MethodType | BuiltinFunctionType | BuiltinMethodType]: ...
100     def ismethoddescriptor(object: object) -> bool: ...
101     def ismemberdescriptor(object: object) -> bool: ...
102
103 else:
104     def isroutine(
105         object: object,
106     ) -> TypeGuard[
107         FunctionType
108         | LambdaType
109         | MethodType
110         | BuiltinFunctionType
111         | BuiltinMethodType
112         | WrapperDescriptorType
113         | MethodDescriptorType
114         | ClassMethodDescriptorType
115     ]: ...
116     def ismethoddescriptor(object: object) -> TypeGuard[MethodDescriptorType]: ...
117     def ismemberdescriptor(object: object) -> TypeGuard[MemberDescriptorType]: ...
118
119 def isabstract(object: object) -> bool: ...
120 def isgetsetdescriptor(object: object) -> TypeGuard[GetSetDescriptorType]: ...
121 def isdatadescriptor(object: object) -> TypeGuard[_SupportsSet[Any, Any] | _SupportsDelete[Any]]: ...
122
123 #
124 # Retrieving source code
125 #
126 _SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType, Callable[..., Any]]
127
128 def findsource(object: _SourceObjectType) -> tuple[list[str], int]: ...
129 def getabsfile(object: _SourceObjectType, _filename: str | None = ...) -> str: ...
130 def getblock(lines: Sequence[str]) -> Sequence[str]: ...
131 def getdoc(object: object) -> str | None: ...
132 def getcomments(object: object) -> str | None: ...
133 def getfile(object: _SourceObjectType) -> str: ...
134 def getmodule(object: object, _filename: str | None = ...) -> ModuleType | None: ...
135 def getsourcefile(object: _SourceObjectType) -> str | None: ...
136 def getsourcelines(object: _SourceObjectType) -> tuple[list[str], int]: ...
137 def getsource(object: _SourceObjectType) -> str: ...
138 def cleandoc(doc: str) -> str: ...
139 def indentsize(line: str) -> int: ...
140
141 #
142 # Introspecting callables with the Signature object
143 #
144 if sys.version_info >= (3, 10):
145     def signature(
146         obj: Callable[..., Any],
147         *,
148         follow_wrapped: bool = ...,
149         globals: Mapping[str, Any] | None = ...,
150         locals: Mapping[str, Any] | None = ...,
151         eval_str: bool = ...,
152     ) -> Signature: ...
153
154 else:
155     def signature(obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ...
156
157 class _void: ...
158 class _empty: ...
159
160 class Signature:
161     def __init__(
162         self, parameters: Sequence[Parameter] | None = ..., *, return_annotation: Any = ..., __validate_parameters__: bool = ...
163     ) -> None: ...
164     empty = _empty
165     @property
166     def parameters(self) -> types.MappingProxyType[str, Parameter]: ...
167     # TODO: can we be more specific here?
168     @property
169     def return_annotation(self) -> Any: ...
170     def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
171     def bind_partial(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
172     def replace(
173         self: Self, *, parameters: Sequence[Parameter] | Type[_void] | None = ..., return_annotation: Any = ...
174     ) -> Self: ...
175     if sys.version_info >= (3, 10):
176         @classmethod
177         def from_callable(
178             cls,
179             obj: Callable[..., Any],
180             *,
181             follow_wrapped: bool = ...,
182             globals: Mapping[str, Any] | None = ...,
183             locals: Mapping[str, Any] | None = ...,
184             eval_str: bool = ...,
185         ) -> Signature: ...
186     else:
187         @classmethod
188         def from_callable(cls, obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ...
189
190 if sys.version_info >= (3, 10):
191     def get_annotations(
192         obj: Callable[..., Any] | Type[Any] | ModuleType,
193         *,
194         globals: Mapping[str, Any] | None = ...,
195         locals: Mapping[str, Any] | None = ...,
196         eval_str: bool = ...,
197     ) -> dict[str, Any]: ...
198
199 # The name is the same as the enum's name in CPython
200 class _ParameterKind(enum.IntEnum):
201     POSITIONAL_ONLY: int
202     POSITIONAL_OR_KEYWORD: int
203     VAR_POSITIONAL: int
204     KEYWORD_ONLY: int
205     VAR_KEYWORD: int
206
207     if sys.version_info >= (3, 8):
208         description: str
209
210 class Parameter:
211     def __init__(self, name: str, kind: _ParameterKind, *, default: Any = ..., annotation: Any = ...) -> None: ...
212     empty = _empty
213     name: str
214     default: Any
215     annotation: Any
216
217     kind: _ParameterKind
218     POSITIONAL_ONLY: ClassVar[Literal[_ParameterKind.POSITIONAL_ONLY]]
219     POSITIONAL_OR_KEYWORD: ClassVar[Literal[_ParameterKind.POSITIONAL_OR_KEYWORD]]
220     VAR_POSITIONAL: ClassVar[Literal[_ParameterKind.VAR_POSITIONAL]]
221     KEYWORD_ONLY: ClassVar[Literal[_ParameterKind.KEYWORD_ONLY]]
222     VAR_KEYWORD: ClassVar[Literal[_ParameterKind.VAR_KEYWORD]]
223     def replace(
224         self: Self,
225         *,
226         name: str | Type[_void] = ...,
227         kind: _ParameterKind | Type[_void] = ...,
228         default: Any = ...,
229         annotation: Any = ...,
230     ) -> Self: ...
231
232 class BoundArguments:
233     arguments: OrderedDict[str, Any]
234     args: Tuple[Any, ...]
235     kwargs: dict[str, Any]
236     signature: Signature
237     def __init__(self, signature: Signature, arguments: OrderedDict[str, Any]) -> None: ...
238     def apply_defaults(self) -> None: ...
239
240 #
241 # Classes and functions
242 #
243
244 # TODO: The actual return type should be list[_ClassTreeItem] but mypy doesn't
245 # seem to be supporting this at the moment:
246 # _ClassTreeItem = list[_ClassTreeItem] | Tuple[type, Tuple[type, ...]]
247 def getclasstree(classes: list[type], unique: bool = ...) -> list[Any]: ...
248 def walktree(classes: list[type], children: dict[Type[Any], list[type]], parent: Type[Any] | None) -> list[Any]: ...
249
250 class ArgSpec(NamedTuple):
251     args: list[str]
252     varargs: str | None
253     keywords: str | None
254     defaults: Tuple[Any, ...]
255
256 class Arguments(NamedTuple):
257     args: list[str]
258     varargs: str | None
259     varkw: str | None
260
261 def getargs(co: CodeType) -> Arguments: ...
262 def getargspec(func: object) -> ArgSpec: ...
263
264 class FullArgSpec(NamedTuple):
265     args: list[str]
266     varargs: str | None
267     varkw: str | None
268     defaults: Tuple[Any, ...] | None
269     kwonlyargs: list[str]
270     kwonlydefaults: dict[str, Any] | None
271     annotations: dict[str, Any]
272
273 def getfullargspec(func: object) -> FullArgSpec: ...
274
275 class ArgInfo(NamedTuple):
276     args: list[str]
277     varargs: str | None
278     keywords: str | None
279     locals: dict[str, Any]
280
281 def getargvalues(frame: FrameType) -> ArgInfo: ...
282 def formatannotation(annotation: object, base_module: str | None = ...) -> str: ...
283 def formatannotationrelativeto(object: object) -> Callable[[object], str]: ...
284 def formatargspec(
285     args: list[str],
286     varargs: str | None = ...,
287     varkw: str | None = ...,
288     defaults: Tuple[Any, ...] | None = ...,
289     kwonlyargs: Sequence[str] | None = ...,
290     kwonlydefaults: dict[str, Any] | None = ...,
291     annotations: dict[str, Any] = ...,
292     formatarg: Callable[[str], str] = ...,
293     formatvarargs: Callable[[str], str] = ...,
294     formatvarkw: Callable[[str], str] = ...,
295     formatvalue: Callable[[Any], str] = ...,
296     formatreturns: Callable[[Any], str] = ...,
297     formatannotation: Callable[[Any], str] = ...,
298 ) -> str: ...
299 def formatargvalues(
300     args: list[str],
301     varargs: str | None,
302     varkw: str | None,
303     locals: dict[str, Any] | None,
304     formatarg: Callable[[str], str] | None = ...,
305     formatvarargs: Callable[[str], str] | None = ...,
306     formatvarkw: Callable[[str], str] | None = ...,
307     formatvalue: Callable[[Any], str] | None = ...,
308 ) -> str: ...
309 def getmro(cls: type) -> Tuple[type, ...]: ...
310 def getcallargs(__func: Callable[..., Any], *args: Any, **kwds: Any) -> dict[str, Any]: ...
311
312 class ClosureVars(NamedTuple):
313     nonlocals: Mapping[str, Any]
314     globals: Mapping[str, Any]
315     builtins: Mapping[str, Any]
316     unbound: set[str]
317
318 def getclosurevars(func: Callable[..., Any]) -> ClosureVars: ...
319 def unwrap(func: Callable[..., Any], *, stop: Callable[[Any], Any] | None = ...) -> Any: ...
320
321 #
322 # The interpreter stack
323 #
324
325 class Traceback(NamedTuple):
326     filename: str
327     lineno: int
328     function: str
329     code_context: list[str] | None
330     index: int | None  # type: ignore
331
332 class FrameInfo(NamedTuple):
333     frame: FrameType
334     filename: str
335     lineno: int
336     function: str
337     code_context: list[str] | None
338     index: int | None  # type: ignore
339
340 def getframeinfo(frame: FrameType | TracebackType, context: int = ...) -> Traceback: ...
341 def getouterframes(frame: Any, context: int = ...) -> list[FrameInfo]: ...
342 def getinnerframes(tb: TracebackType, context: int = ...) -> list[FrameInfo]: ...
343 def getlineno(frame: FrameType) -> int: ...
344 def currentframe() -> FrameType | None: ...
345 def stack(context: int = ...) -> list[FrameInfo]: ...
346 def trace(context: int = ...) -> list[FrameInfo]: ...
347
348 #
349 # Fetching attributes statically
350 #
351
352 def getattr_static(obj: object, attr: str, default: Any | None = ...) -> Any: ...
353
354 #
355 # Current State of Generators and Coroutines
356 #
357
358 # TODO In the next two blocks of code, can we be more specific regarding the
359 # type of the "enums"?
360
361 GEN_CREATED: str
362 GEN_RUNNING: str
363 GEN_SUSPENDED: str
364 GEN_CLOSED: str
365
366 def getgeneratorstate(generator: Generator[Any, Any, Any]) -> str: ...
367
368 CORO_CREATED: str
369 CORO_RUNNING: str
370 CORO_SUSPENDED: str
371 CORO_CLOSED: str
372 # TODO can we be more specific than "object"?
373 def getcoroutinestate(coroutine: object) -> str: ...
374 def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> dict[str, Any]: ...
375
376 # TODO can we be more specific than "object"?
377 def getcoroutinelocals(coroutine: object) -> dict[str, Any]: ...
378
379 # Create private type alias to avoid conflict with symbol of same
380 # name created in Attribute class.
381 _Object = object
382
383 class Attribute(NamedTuple):
384     name: str
385     kind: str
386     defining_class: type
387     object: _Object
388
389 def classify_class_attrs(cls: type) -> list[Attribute]: ...
390
391 if sys.version_info >= (3, 9):
392     class ClassFoundException(Exception): ...