_inspect.pyi 2.2 KB

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