Format: application/octet-stream
⬇ Download File (9.7 KB)
   1  import enum
   2  import sys
   3  from collections import OrderedDict
   4  from types import CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
   5  from typing import (
   6      AbstractSet,
   7      Any,
   8      Callable,
   9      ClassVar,
  10      Dict,
  11      Generator,
  12      List,
  13      Mapping,
  14      NamedTuple,
  15      Optional,
  16      Sequence,
  17      Tuple,
  18      Type,
  19      Union,
  20  )
  21  from typing_extensions import Literal
  22  
  23  #
  24  # Types and members
  25  #
  26  class EndOfBlock(Exception): ...
  27  
  28  class BlockFinder:
  29      indent: int
  30      islambda: bool
  31      started: bool
  32      passline: bool
  33      indecorator: bool
  34      decoratorhasargs: bool
  35      last: int
  36      def tokeneater(self, type: int, token: str, srowcol: Tuple[int, int], erowcol: Tuple[int, int], line: str) -> None: ...
  37  
  38  CO_OPTIMIZED: int
  39  CO_NEWLOCALS: int
  40  CO_VARARGS: int
  41  CO_VARKEYWORDS: int
  42  CO_NESTED: int
  43  CO_GENERATOR: int
  44  CO_NOFREE: int
  45  CO_COROUTINE: int
  46  CO_ITERABLE_COROUTINE: int
  47  CO_ASYNC_GENERATOR: int
  48  TPFLAGS_IS_ABSTRACT: int
  49  
  50  def getmembers(object: object, predicate: Optional[Callable[[Any], bool]] = ...) -> List[Tuple[str, Any]]: ...
  51  def getmodulename(path: str) -> Optional[str]: ...
  52  def ismodule(object: object) -> bool: ...
  53  def isclass(object: object) -> bool: ...
  54  def ismethod(object: object) -> bool: ...
  55  def isfunction(object: object) -> bool: ...
  56  
  57  if sys.version_info >= (3, 8):
  58      def isgeneratorfunction(obj: object) -> bool: ...
  59      def iscoroutinefunction(obj: object) -> bool: ...
  60  
  61  else:
  62      def isgeneratorfunction(object: object) -> bool: ...
  63      def iscoroutinefunction(object: object) -> bool: ...
  64  
  65  def isgenerator(object: object) -> bool: ...
  66  def iscoroutine(object: object) -> bool: ...
  67  def isawaitable(object: object) -> bool: ...
  68  
  69  if sys.version_info >= (3, 8):
  70      def isasyncgenfunction(obj: object) -> bool: ...
  71  
  72  else:
  73      def isasyncgenfunction(object: object) -> bool: ...
  74  
  75  def isasyncgen(object: object) -> bool: ...
  76  def istraceback(object: object) -> bool: ...
  77  def isframe(object: object) -> bool: ...
  78  def iscode(object: object) -> bool: ...
  79  def isbuiltin(object: object) -> bool: ...
  80  def isroutine(object: object) -> bool: ...
  81  def isabstract(object: object) -> bool: ...
  82  def ismethoddescriptor(object: object) -> bool: ...
  83  def isdatadescriptor(object: object) -> bool: ...
  84  def isgetsetdescriptor(object: object) -> bool: ...
  85  def ismemberdescriptor(object: object) -> bool: ...
  86  
  87  #
  88  # Retrieving source code
  89  #
  90  _SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType, Callable[..., Any]]
  91  
  92  def findsource(object: _SourceObjectType) -> Tuple[List[str], int]: ...
  93  def getabsfile(object: _SourceObjectType, _filename: Optional[str] = ...) -> str: ...
  94  def getblock(lines: Sequence[str]) -> Sequence[str]: ...
  95  def getdoc(object: object) -> Optional[str]: ...
  96  def getcomments(object: object) -> Optional[str]: ...
  97  def getfile(object: _SourceObjectType) -> str: ...
  98  def getmodule(object: object, _filename: Optional[str] = ...) -> Optional[ModuleType]: ...
  99  def getsourcefile(object: _SourceObjectType) -> Optional[str]: ...
 100  def getsourcelines(object: _SourceObjectType) -> Tuple[List[str], int]: ...
 101  def getsource(object: _SourceObjectType) -> str: ...
 102  def cleandoc(doc: str) -> str: ...
 103  def indentsize(line: str) -> int: ...
 104  
 105  #
 106  # Introspecting callables with the Signature object
 107  #
 108  def signature(obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ...
 109  
 110  class Signature:
 111      def __init__(self, parameters: Optional[Sequence[Parameter]] = ..., *, return_annotation: Any = ...) -> None: ...
 112      # TODO: can we be more specific here?
 113      empty: object = ...
 114  
 115      parameters: Mapping[str, Parameter]
 116  
 117      # TODO: can we be more specific here?
 118      return_annotation: Any
 119      def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
 120      def bind_partial(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
 121      def replace(self, *, parameters: Optional[Sequence[Parameter]] = ..., return_annotation: Any = ...) -> Signature: ...
 122      @classmethod
 123      def from_callable(cls, obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ...
 124  
 125  # The name is the same as the enum's name in CPython
 126  class _ParameterKind(enum.IntEnum):
 127      POSITIONAL_ONLY: int
 128      POSITIONAL_OR_KEYWORD: int
 129      VAR_POSITIONAL: int
 130      KEYWORD_ONLY: int
 131      VAR_KEYWORD: int
 132  
 133      if sys.version_info >= (3, 8):
 134          description: str
 135  
 136  class Parameter:
 137      def __init__(self, name: str, kind: _ParameterKind, *, default: Any = ..., annotation: Any = ...) -> None: ...
 138      empty: Any = ...
 139      name: str
 140      default: Any
 141      annotation: Any
 142  
 143      kind: _ParameterKind
 144      POSITIONAL_ONLY: ClassVar[Literal[_ParameterKind.POSITIONAL_ONLY]]
 145      POSITIONAL_OR_KEYWORD: ClassVar[Literal[_ParameterKind.POSITIONAL_OR_KEYWORD]]
 146      VAR_POSITIONAL: ClassVar[Literal[_ParameterKind.VAR_POSITIONAL]]
 147      KEYWORD_ONLY: ClassVar[Literal[_ParameterKind.KEYWORD_ONLY]]
 148      VAR_KEYWORD: ClassVar[Literal[_ParameterKind.VAR_KEYWORD]]
 149      def replace(
 150          self, *, name: Optional[str] = ..., kind: Optional[_ParameterKind] = ..., default: Any = ..., annotation: Any = ...
 151      ) -> Parameter: ...
 152  
 153  class BoundArguments:
 154      arguments: OrderedDict[str, Any]
 155      args: Tuple[Any, ...]
 156      kwargs: Dict[str, Any]
 157      signature: Signature
 158      def __init__(self, signature: Signature, arguments: OrderedDict[str, Any]) -> None: ...
 159      def apply_defaults(self) -> None: ...
 160  
 161  #
 162  # Classes and functions
 163  #
 164  
 165  # TODO: The actual return type should be List[_ClassTreeItem] but mypy doesn't
 166  # seem to be supporting this at the moment:
 167  # _ClassTreeItem = Union[List[_ClassTreeItem], Tuple[type, Tuple[type, ...]]]
 168  def getclasstree(classes: List[type], unique: bool = ...) -> Any: ...
 169  
 170  class ArgSpec(NamedTuple):
 171      args: List[str]
 172      varargs: Optional[str]
 173      keywords: Optional[str]
 174      defaults: Tuple[Any, ...]
 175  
 176  class Arguments(NamedTuple):
 177      args: List[str]
 178      varargs: Optional[str]
 179      varkw: Optional[str]
 180  
 181  def getargs(co: CodeType) -> Arguments: ...
 182  def getargspec(func: object) -> ArgSpec: ...
 183  
 184  class FullArgSpec(NamedTuple):
 185      args: List[str]
 186      varargs: Optional[str]
 187      varkw: Optional[str]
 188      defaults: Optional[Tuple[Any, ...]]
 189      kwonlyargs: List[str]
 190      kwonlydefaults: Optional[Dict[str, Any]]
 191      annotations: Dict[str, Any]
 192  
 193  def getfullargspec(func: object) -> FullArgSpec: ...
 194  
 195  class ArgInfo(NamedTuple):
 196      args: List[str]
 197      varargs: Optional[str]
 198      keywords: Optional[str]
 199      locals: Dict[str, Any]
 200  
 201  def getargvalues(frame: FrameType) -> ArgInfo: ...
 202  def formatannotation(annotation: object, base_module: Optional[str] = ...) -> str: ...
 203  def formatannotationrelativeto(object: object) -> Callable[[object], str]: ...
 204  def formatargspec(
 205      args: List[str],
 206      varargs: Optional[str] = ...,
 207      varkw: Optional[str] = ...,
 208      defaults: Optional[Tuple[Any, ...]] = ...,
 209      kwonlyargs: Optional[Sequence[str]] = ...,
 210      kwonlydefaults: Optional[Dict[str, Any]] = ...,
 211      annotations: Dict[str, Any] = ...,
 212      formatarg: Callable[[str], str] = ...,
 213      formatvarargs: Callable[[str], str] = ...,
 214      formatvarkw: Callable[[str], str] = ...,
 215      formatvalue: Callable[[Any], str] = ...,
 216      formatreturns: Callable[[Any], str] = ...,
 217      formatannotation: Callable[[Any], str] = ...,
 218  ) -> str: ...
 219  def formatargvalues(
 220      args: List[str],
 221      varargs: Optional[str],
 222      varkw: Optional[str],
 223      locals: Optional[Dict[str, Any]],
 224      formatarg: Optional[Callable[[str], str]] = ...,
 225      formatvarargs: Optional[Callable[[str], str]] = ...,
 226      formatvarkw: Optional[Callable[[str], str]] = ...,
 227      formatvalue: Optional[Callable[[Any], str]] = ...,
 228  ) -> str: ...
 229  def getmro(cls: type) -> Tuple[type, ...]: ...
 230  def getcallargs(__func: Callable[..., Any], *args: Any, **kwds: Any) -> Dict[str, Any]: ...
 231  
 232  class ClosureVars(NamedTuple):
 233      nonlocals: Mapping[str, Any]
 234      globals: Mapping[str, Any]
 235      builtins: Mapping[str, Any]
 236      unbound: AbstractSet[str]
 237  
 238  def getclosurevars(func: Callable[..., Any]) -> ClosureVars: ...
 239  def unwrap(func: Callable[..., Any], *, stop: Optional[Callable[[Any], Any]] = ...) -> Any: ...
 240  
 241  #
 242  # The interpreter stack
 243  #
 244  
 245  class Traceback(NamedTuple):
 246      filename: str
 247      lineno: int
 248      function: str
 249      code_context: Optional[List[str]]
 250      index: Optional[int]  # type: ignore
 251  
 252  class FrameInfo(NamedTuple):
 253      frame: FrameType
 254      filename: str
 255      lineno: int
 256      function: str
 257      code_context: Optional[List[str]]
 258      index: Optional[int]  # type: ignore
 259  
 260  def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ...
 261  def getouterframes(frame: Any, context: int = ...) -> List[FrameInfo]: ...
 262  def getinnerframes(tb: TracebackType, context: int = ...) -> List[FrameInfo]: ...
 263  def getlineno(frame: FrameType) -> int: ...
 264  def currentframe() -> Optional[FrameType]: ...
 265  def stack(context: int = ...) -> List[FrameInfo]: ...
 266  def trace(context: int = ...) -> List[FrameInfo]: ...
 267  
 268  #
 269  # Fetching attributes statically
 270  #
 271  
 272  def getattr_static(obj: object, attr: str, default: Optional[Any] = ...) -> Any: ...
 273  
 274  #
 275  # Current State of Generators and Coroutines
 276  #
 277  
 278  # TODO In the next two blocks of code, can we be more specific regarding the
 279  # type of the "enums"?
 280  
 281  GEN_CREATED: str
 282  GEN_RUNNING: str
 283  GEN_SUSPENDED: str
 284  GEN_CLOSED: str
 285  
 286  def getgeneratorstate(generator: Generator[Any, Any, Any]) -> str: ...
 287  
 288  CORO_CREATED: str
 289  CORO_RUNNING: str
 290  CORO_SUSPENDED: str
 291  CORO_CLOSED: str
 292  # TODO can we be more specific than "object"?
 293  def getcoroutinestate(coroutine: object) -> str: ...
 294  def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> Dict[str, Any]: ...
 295  
 296  # TODO can we be more specific than "object"?
 297  def getcoroutinelocals(coroutine: object) -> Dict[str, Any]: ...
 298  
 299  # Create private type alias to avoid conflict with symbol of same
 300  # name created in Attribute class.
 301  _Object = object
 302  
 303  class Attribute(NamedTuple):
 304      name: str
 305      kind: str
 306      defining_class: type
 307      object: _Object
 308  
 309  def classify_class_attrs(cls: type) -> List[Attribute]: ...
 310