--- /dev/null
+import sys\r
+from typing import (AbstractSet, Any, Callable, Dict, Generator, List, Mapping,\r
+ MutableMapping, NamedTuple, Optional, Sequence, Tuple,\r
+ Union,\r
+ )\r
+from types import CodeType, FrameType, ModuleType, TracebackType\r
+\r
+#\r
+# Types and members\r
+#\r
+class EndOfBlock(Exception): ...\r
+\r
+class BlockFinder:\r
+ indent: int\r
+ islambda: bool\r
+ started: bool\r
+ passline: bool\r
+ indecorator: bool\r
+ decoratorhasargs: bool\r
+ last: int\r
+ def tokeneater(self, type: int, token: str, srow_scol: Tuple[int, int],\r
+ erow_ecol: Tuple[int, int], line: str) -> None: ...\r
+\r
+CO_OPTIMIZED: int\r
+CO_NEWLOCALS: int\r
+CO_VARARGS: int\r
+CO_VARKEYWORDS: int\r
+CO_NESTED: int\r
+CO_GENERATOR: int\r
+CO_NOFREE: int\r
+if sys.version_info >= (3, 5):\r
+ CO_COROUTINE: int\r
+ CO_ITERABLE_COROUTINE: int\r
+if sys.version_info >= (3, 6):\r
+ CO_ASYNC_GENERATOR: int\r
+TPFLAGS_IS_ABSTRACT: int\r
+\r
+if sys.version_info < (3, 6):\r
+ ModuleInfo = NamedTuple('ModuleInfo', [('name', str),\r
+ ('suffix', str),\r
+ ('mode', str),\r
+ ('module_type', int),\r
+ ])\r
+ def getmoduleinfo(path: str) -> Optional[ModuleInfo]: ...\r
+\r
+def getmembers(object: object,\r
+ predicate: Optional[Callable[[Any], bool]] = ...,\r
+ ) -> List[Tuple[str, Any]]: ...\r
+def getmodulename(path: str) -> Optional[str]: ...\r
+\r
+def ismodule(object: object) -> bool: ...\r
+def isclass(object: object) -> bool: ...\r
+def ismethod(object: object) -> bool: ...\r
+def isfunction(object: object) -> bool: ...\r
+def isgeneratorfunction(object: object) -> bool: ...\r
+def isgenerator(object: object) -> bool: ...\r
+\r
+if sys.version_info >= (3, 5):\r
+ def iscoroutinefunction(object: object) -> bool: ...\r
+ def iscoroutine(object: object) -> bool: ...\r
+ def isawaitable(object: object) -> bool: ...\r
+if sys.version_info >= (3, 6):\r
+ def isasyncgenfunction(object: object) -> bool: ...\r
+ def isasyncgen(object: object) -> bool: ...\r
+def istraceback(object: object) -> bool: ...\r
+def isframe(object: object) -> bool: ...\r
+def iscode(object: object) -> bool: ...\r
+def isbuiltin(object: object) -> bool: ...\r
+def isroutine(object: object) -> bool: ...\r
+def isabstract(object: object) -> bool: ...\r
+def ismethoddescriptor(object: object) -> bool: ...\r
+def isdatadescriptor(object: object) -> bool: ...\r
+def isgetsetdescriptor(object: object) -> bool: ...\r
+def ismemberdescriptor(object: object) -> bool: ...\r
+\r
+\r
+#\r
+# Retrieving source code\r
+#\r
+def findsource(object: object) -> Tuple[List[str], int]: ...\r
+def getabsfile(object: object) -> str: ...\r
+def getblock(lines: Sequence[str]) -> Sequence[str]: ...\r
+def getdoc(object: object) -> str: ...\r
+def getcomments(object: object) -> str: ...\r
+def getfile(object: object) -> str: ...\r
+def getmodule(object: object) -> ModuleType: ...\r
+def getsourcefile(object: object) -> str: ...\r
+# TODO restrict to "module, class, method, function, traceback, frame,\r
+# or code object"\r
+def getsourcelines(object: object) -> Tuple[List[str], int]: ...\r
+# TODO restrict to "a module, class, method, function, traceback, frame,\r
+# or code object"\r
+def getsource(object: object) -> str: ...\r
+def cleandoc(doc: str) -> str: ...\r
+def indentsize(line: str) -> int: ...\r
+\r
+\r
+#\r
+# Introspecting callables with the Signature object\r
+#\r
+def signature(callable: Callable[..., Any],\r
+ *,\r
+ follow_wrapped: bool = ...) -> 'Signature': ...\r
+\r
+class Signature:\r
+ def __init__(self,\r
+ parameters: Optional[Sequence['Parameter']] = ...,\r
+ *,\r
+ return_annotation: Any = ...) -> None: ...\r
+ # TODO: can we be more specific here?\r
+ empty: object = ...\r
+\r
+ parameters: Mapping[str, 'Parameter']\r
+\r
+ # TODO: can we be more specific here?\r
+ return_annotation: Any\r
+\r
+ def bind(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ...\r
+ def bind_partial(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ...\r
+ def replace(self,\r
+ *,\r
+ parameters: Optional[Sequence['Parameter']] = ...,\r
+ return_annotation: Any = ...) -> 'Signature': ...\r
+\r
+ if sys.version_info >= (3, 5):\r
+ @classmethod\r
+ def from_callable(cls,\r
+ obj: Callable[..., Any],\r
+ *,\r
+ follow_wrapped: bool = ...) -> 'Signature': ...\r
+\r
+# The name is the same as the enum's name in CPython\r
+class _ParameterKind: ...\r
+\r
+class Parameter:\r
+ def __init__(self,\r
+ name: str,\r
+ kind: _ParameterKind,\r
+ *,\r
+ default: Any = ...,\r
+ annotation: Any = ...) -> None: ...\r
+ empty: Any = ...\r
+ name: str\r
+ default: Any\r
+ annotation: Any\r
+\r
+ kind: _ParameterKind\r
+ POSITIONAL_ONLY: _ParameterKind = ...\r
+ POSITIONAL_OR_KEYWORD: _ParameterKind = ...\r
+ VAR_POSITIONAL: _ParameterKind = ...\r
+ KEYWORD_ONLY: _ParameterKind = ...\r
+ VAR_KEYWORD: _ParameterKind = ...\r
+\r
+ def replace(self,\r
+ *,\r
+ name: Optional[str] = ...,\r
+ kind: Optional[_ParameterKind] = ...,\r
+ default: Any = ...,\r
+ annotation: Any = ...) -> 'Parameter': ...\r
+\r
+class BoundArguments:\r
+ arguments: MutableMapping[str, Any]\r
+ args: Tuple[Any, ...]\r
+ kwargs: Dict[str, Any]\r
+ signature: Signature\r
+\r
+ if sys.version_info >= (3, 5):\r
+ def apply_defaults(self) -> None: ...\r
+\r
+\r
+#\r
+# Classes and functions\r
+#\r
+\r
+# TODO: The actual return type should be List[_ClassTreeItem] but mypy doesn't\r
+# seem to be supporting this at the moment:\r
+# _ClassTreeItem = Union[List['_ClassTreeItem'], Tuple[type, Tuple[type, ...]]]\r
+def getclasstree(classes: List[type], unique: bool = ...) -> Any: ...\r
+\r
+ArgSpec = NamedTuple('ArgSpec', [('args', List[str]),\r
+ ('varargs', str),\r
+ ('keywords', str),\r
+ ('defaults', tuple),\r
+ ])\r
+\r
+Arguments = NamedTuple('Arguments', [('args', List[str]),\r
+ ('varargs', Optional[str]),\r
+ ('varkw', Optional[str]),\r
+ ])\r
+\r
+def getargs(co: CodeType) -> Arguments: ...\r
+def getargspec(func: object) -> ArgSpec: ...\r
+\r
+FullArgSpec = NamedTuple('FullArgSpec', [('args', List[str]),\r
+ ('varargs', str),\r
+ ('varkw', str),\r
+ ('defaults', tuple),\r
+ ('kwonlyargs', List[str]),\r
+ ('kwonlydefaults', Dict[str, Any]),\r
+ ('annotations', Dict[str, Any]),\r
+ ])\r
+\r
+def getfullargspec(func: object) -> FullArgSpec: ...\r
+\r
+# TODO make the field types more specific here\r
+ArgInfo = NamedTuple('ArgInfo', [('args', List[str]),\r
+ ('varargs', Optional[str]),\r
+ ('keywords', Optional[str]),\r
+ ('locals', Dict[str, Any]),\r
+ ])\r
+\r
+def getargvalues(frame: FrameType) -> ArgInfo: ...\r
+def formatannotation(annotation: object, base_module: Optional[str] = ...) -> str: ...\r
+def formatannotationrelativeto(object: object) -> Callable[[object], str]: ...\r
+def formatargspec(args: List[str],\r
+ varargs: Optional[str] = ...,\r
+ varkw: Optional[str] = ...,\r
+ defaults: Optional[Tuple[Any, ...]] = ...,\r
+ kwonlyargs: Optional[List[str]] = ...,\r
+ kwonlydefaults: Optional[Dict[str, Any]] = ...,\r
+ annotations: Dict[str, Any] = ...,\r
+ formatarg: Callable[[str], str] = ...,\r
+ formatvarargs: Callable[[str], str] = ...,\r
+ formatvarkw: Callable[[str], str] = ...,\r
+ formatvalue: Callable[[Any], str] = ...,\r
+ formatreturns: Callable[[Any], str] = ...,\r
+ formatannotations: Callable[[Any], str] = ...,\r
+ ) -> str: ...\r
+def formatargvalues(args: List[str],\r
+ varargs: Optional[str] = ...,\r
+ varkw: Optional[str] = ...,\r
+ locals: Optional[Dict[str, Any]] = ...,\r
+ formatarg: Optional[Callable[[str], str]] = ...,\r
+ formatvarargs: Optional[Callable[[str], str]] = ...,\r
+ formatvarkw: Optional[Callable[[str], str]] = ...,\r
+ formatvalue: Optional[Callable[[Any], str]] = ...,\r
+ ) -> str: ...\r
+def getmro(cls: type) -> Tuple[type, ...]: ...\r
+\r
+def getcallargs(func: Callable[..., Any],\r
+ *args: Any,\r
+ **kwds: Any) -> Dict[str, Any]: ...\r
+\r
+\r
+ClosureVars = NamedTuple('ClosureVars', [('nonlocals', Mapping[str, Any]),\r
+ ('globals', Mapping[str, Any]),\r
+ ('builtins', Mapping[str, Any]),\r
+ ('unbound', AbstractSet[str]),\r
+ ])\r
+def getclosurevars(func: Callable[..., Any]) -> ClosureVars: ...\r
+\r
+def unwrap(func: Callable[..., Any],\r
+ *,\r
+ stop: Callable[[Any], Any]) -> Any: ...\r
+\r
+\r
+#\r
+# The interpreter stack\r
+#\r
+\r
+Traceback = NamedTuple(\r
+ 'Traceback',\r
+ [\r
+ ('filename', str),\r
+ ('lineno', int),\r
+ ('function', str),\r
+ ('code_context', List[str]),\r
+ ('index', int),\r
+ ]\r
+)\r
+\r
+# Python 3.5+ (functions returning it used to return regular tuples)\r
+FrameInfo = NamedTuple('FrameInfo', [('frame', FrameType),\r
+ ('filename', str),\r
+ ('lineno', int),\r
+ ('function', str),\r
+ ('code_context', List[str]),\r
+ ('index', int),\r
+ ])\r
+\r
+def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ...\r
+def getouterframes(frame: Any, context: int = ...) -> List[FrameInfo]: ...\r
+def getinnerframes(traceback: TracebackType, context: int = ...) -> List[FrameInfo]: ...\r
+def getlineno(frame: FrameType) -> int: ...\r
+def currentframe() -> Optional[FrameType]: ...\r
+def stack(context: int = ...) -> List[FrameInfo]: ...\r
+def trace(context: int = ...) -> List[FrameInfo]: ...\r
+\r
+#\r
+# Fetching attributes statically\r
+#\r
+\r
+def getattr_static(obj: object, attr: str, default: Optional[Any] = ...) -> Any: ...\r
+\r
+\r
+#\r
+# Current State of Generators and Coroutines\r
+#\r
+\r
+# TODO In the next two blocks of code, can we be more specific regarding the\r
+# type of the "enums"?\r
+\r
+GEN_CREATED: str\r
+GEN_RUNNING: str\r
+GEN_SUSPENDED: str\r
+GEN_CLOSED: str\r
+def getgeneratorstate(generator: Generator[Any, Any, Any]) -> str: ...\r
+\r
+if sys.version_info >= (3, 5):\r
+ CORO_CREATED: str\r
+ CORO_RUNNING: str\r
+ CORO_SUSPENDED: str\r
+ CORO_CLOSED: str\r
+ # TODO can we be more specific than "object"?\r
+ def getcoroutinestate(coroutine: object) -> str: ...\r
+\r
+def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> Dict[str, Any]: ...\r
+\r
+if sys.version_info >= (3, 5):\r
+ # TODO can we be more specific than "object"?\r
+ def getcoroutinelocals(coroutine: object) -> Dict[str, Any]: ...\r
+\r
+Attribute = NamedTuple('Attribute', [('name', str),\r
+ ('kind', str),\r
+ ('defining_class', type),\r
+ ('object', object),\r
+ ])\r
+\r
+def classify_class_attrs(cls: type) -> List[Attribute]: ...\r