Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_inspect.pyi71 linesDownload Raw Back to _utils
1import types
2from _typeshed import SupportsLenAndGetItem
3from collections.abc import Callable, Mapping
4from typing import Any, Final, TypeAlias, TypeVar, overload
5from typing_extensions import TypeIs
6
7__all__ = ["formatargspec", "getargspec"]
8
9###
10
11_T = TypeVar("_T")
12_RT = TypeVar("_RT")
13
14_StrSeq: TypeAlias = SupportsLenAndGetItem[str]
15_NestedSeq: TypeAlias = list[_T | _NestedSeq[_T]] | tuple[_T | _NestedSeq[_T], ...]
16
17_JoinFunc: TypeAlias = Callable[[list[_T]], _T]
18_FormatFunc: TypeAlias = Callable[[_T], str]
19
20###
21
22CO_OPTIMIZED: Final = 1
23CO_NEWLOCALS: Final = 2
24CO_VARARGS: Final = 4
25CO_VARKEYWORDS: Final = 8
26
27###
28
29def ismethod(object: object) -> TypeIs[types.MethodType]: ...
30def isfunction(object: object) -> TypeIs[types.FunctionType]: ...
31def iscode(object: object) -> TypeIs[types.CodeType]: ...
32
33###
34
35def getargs(co: types.CodeType) -> tuple[list[str], str | None, str | None]: ...
36def getargspec(func: types.MethodType | types.FunctionType) -> tuple[list[str], str | None, str | None, tuple[Any, ...]]: ...
37def getargvalues(frame: types.FrameType) -> tuple[list[str], str | None, str | None, dict[str, Any]]: ...
38
39#
40def joinseq(seq: _StrSeq) -> str: ...
41
42#
43@overload
44def strseq(object: _NestedSeq[str], convert: Callable[[Any], Any], join: _JoinFunc[str] = ...) -> str: ...
45@overload
46def strseq(object: _NestedSeq[_T], convert: Callable[[_T], _RT], join: _JoinFunc[_RT]) -> _RT: ...
47
48#
49def formatargspec(
50    args: _StrSeq,
51    varargs: str | None = None,
52    varkw: str | None = None,
53    defaults: SupportsLenAndGetItem[object] | None = None,
54    formatarg: _FormatFunc[str] = ...,  # str
55    formatvarargs: _FormatFunc[str] = ...,  # "*{}".format
56    formatvarkw: _FormatFunc[str] = ...,  # "**{}".format
57    formatvalue: _FormatFunc[object] = ...,  # "={!r}".format
58    join: _JoinFunc[str] = ...,  # joinseq
59) -> str: ...
60def formatargvalues(
61    args: _StrSeq,
62    varargs: str | None,
63    varkw: str | None,
64    locals: Mapping[str, object] | None,
65    formatarg: _FormatFunc[str] = ...,  # str
66    formatvarargs: _FormatFunc[str] = ...,  # "*{}".format
67    formatvarkw: _FormatFunc[str] = ...,  # "**{}".format
68    formatvalue: _FormatFunc[object] = ...,  # "={!r}".format
69    join: _JoinFunc[str] = ...,  # joinseq
70) -> str: ...
71