--- /dev/null
+# Stubs for types\r
+# Note, all classes "defined" here require special handling.\r
+\r
+# TODO parts of this should be conditional on version\r
+\r
+import sys\r
+from typing import (\r
+ Any, Awaitable, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar,\r
+ Union, overload, Type\r
+)\r
+\r
+# ModuleType is exported from this module, but for circular import\r
+# reasons exists in its own stub file (with ModuleSpec and Loader).\r
+from _importlib_modulespec import ModuleType as ModuleType # Exported\r
+\r
+_T = TypeVar('_T')\r
+_T_co = TypeVar('_T_co', covariant=True)\r
+_T_contra = TypeVar('_T_contra', contravariant=True)\r
+_KT = TypeVar('_KT')\r
+_VT = TypeVar('_VT')\r
+\r
+class _Cell:\r
+ cell_contents = ... # type: Any\r
+\r
+class FunctionType:\r
+ __closure__ = ... # type: Optional[Tuple[_Cell, ...]]\r
+ __code__ = ... # type: CodeType\r
+ __defaults__ = ... # type: Optional[Tuple[Any, ...]]\r
+ __dict__ = ... # type: Dict[str, Any]\r
+ __globals__ = ... # type: Dict[str, Any]\r
+ __name__ = ... # type: str\r
+ __qualname__ = ... # type: str\r
+ __annotations__ = ... # type: Dict[str, Any]\r
+ __kwdefaults__ = ... # type: Dict[str, Any]\r
+ def __call__(self, *args: Any, **kwargs: Any) -> Any: ...\r
+ def __get__(self, obj: Optional[object], type: Optional[type]) -> 'MethodType': ...\r
+LambdaType = FunctionType\r
+\r
+class CodeType:\r
+ """Create a code object. Not for the faint of heart."""\r
+ co_argcount = ... # type: int\r
+ co_kwonlyargcount = ... # type: int\r
+ co_nlocals = ... # type: int\r
+ co_stacksize = ... # type: int\r
+ co_flags = ... # type: int\r
+ co_code = ... # type: bytes\r
+ co_consts = ... # type: Tuple[Any, ...]\r
+ co_names = ... # type: Tuple[str, ...]\r
+ co_varnames = ... # type: Tuple[str, ...]\r
+ co_filename = ... # type: Optional[str]\r
+ co_name = ... # type: str\r
+ co_firstlineno = ... # type: int\r
+ co_lnotab = ... # type: bytes\r
+ co_freevars = ... # type: Tuple[str, ...]\r
+ co_cellvars = ... # type: Tuple[str, ...]\r
+ def __init__(\r
+ self,\r
+ argcount: int,\r
+ kwonlyargcount: int,\r
+ nlocals: int,\r
+ stacksize: int,\r
+ flags: int,\r
+ codestring: bytes,\r
+ constants: Tuple[Any, ...],\r
+ names: Tuple[str, ...],\r
+ varnames: Tuple[str, ...],\r
+ filename: str,\r
+ name: str,\r
+ firstlineno: int,\r
+ lnotab: bytes,\r
+ freevars: Tuple[str, ...] = ...,\r
+ cellvars: Tuple[str, ...] = ...,\r
+ ) -> None: ...\r
+\r
+class MappingProxyType(Mapping[_KT, _VT], Generic[_KT, _VT]):\r
+ def __init__(self, mapping: Mapping[_KT, _VT]) -> None: ...\r
+ def __getitem__(self, k: _KT) -> _VT: ...\r
+ def __iter__(self) -> Iterator[_KT]: ...\r
+ def __len__(self) -> int: ...\r
+\r
+class SimpleNamespace:\r
+ def __init__(self, **kwargs: Any) -> None: ...\r
+ def __getattribute__(self, name: str) -> Any: ...\r
+ def __setattr__(self, name: str, value: Any) -> None: ...\r
+ def __delattr__(self, name: str) -> None: ...\r
+\r
+class GeneratorType:\r
+ gi_code = ... # type: CodeType\r
+ gi_frame = ... # type: FrameType\r
+ gi_running = ... # type: bool\r
+ gi_yieldfrom = ... # type: Optional[GeneratorType]\r
+ def __iter__(self) -> 'GeneratorType': ...\r
+ def __next__(self) -> Any: ...\r
+ def close(self) -> None: ...\r
+ def send(self, arg: Any) -> Any: ...\r
+ @overload\r
+ def throw(self, val: BaseException) -> Any: ...\r
+ @overload\r
+ def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...\r
+\r
+if sys.version_info >= (3, 6):\r
+ class AsyncGeneratorType(Generic[_T_co, _T_contra]):\r
+ ag_await: Optional[Awaitable[Any]]\r
+ ag_frame: FrameType\r
+ ag_running: bool\r
+ ag_code: CodeType\r
+ def __aiter__(self) -> Awaitable[AsyncGeneratorType[_T_co, _T_contra]]: ...\r
+ def __anext__(self) -> Awaitable[_T_co]: ...\r
+ def asend(self, val: _T_contra) -> Awaitable[_T_co]: ...\r
+ @overload\r
+ def athrow(self, val: BaseException) -> Awaitable[_T_co]: ...\r
+ @overload\r
+ def athrow(self, typ: Type[BaseException], val: BaseException, tb: TracebackType = ...) -> Awaitable[_T_co]: ...\r
+ def aclose(self) -> Awaitable[_T_co]: ...\r
+\r
+class CoroutineType:\r
+ cr_await = ... # type: Optional[Any]\r
+ cr_code = ... # type: CodeType\r
+ cr_frame = ... # type: FrameType\r
+ cr_running = ... # type: bool\r
+ def close(self) -> None: ...\r
+ def send(self, arg: Any) -> Any: ...\r
+ @overload\r
+ def throw(self, val: BaseException) -> Any: ...\r
+ @overload\r
+ def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...\r
+\r
+class _StaticFunctionType:\r
+ """Fictional type to correct the type of MethodType.__func__.\r
+\r
+ FunctionType is a descriptor, so mypy follows the descriptor protocol and\r
+ converts MethodType.__func__ back to MethodType (the return type of\r
+ FunctionType.__get__). But this is actually a special case; MethodType is\r
+ implemented in C and its attribute access doesn't go through\r
+ __getattribute__.\r
+\r
+ By wrapping FunctionType in _StaticFunctionType, we get the right result;\r
+ similar to wrapping a function in staticmethod() at runtime to prevent it\r
+ being bound as a method.\r
+ """\r
+ def __get__(self, obj: Optional[object], type: Optional[type]) -> 'FunctionType': ...\r
+\r
+class MethodType:\r
+ __func__ = ... # type: _StaticFunctionType\r
+ __self__ = ... # type: object\r
+ __name__ = ... # type: str\r
+ __qualname__ = ... # type: str\r
+ def __init__(self, func: Callable, obj: object) -> None: ...\r
+ def __call__(self, *args: Any, **kwargs: Any) -> Any: ...\r
+class BuiltinFunctionType:\r
+ __self__ = ... # type: Union[object, ModuleType]\r
+ __name__ = ... # type: str\r
+ __qualname__ = ... # type: str\r
+ def __call__(self, *args: Any, **kwargs: Any) -> Any: ...\r
+BuiltinMethodType = BuiltinFunctionType\r
+\r
+class TracebackType:\r
+ if sys.version_info >= (3, 7):\r
+ def __init__(self, tb_next: Optional[TracebackType], tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ...\r
+ tb_next: Optional[TracebackType]\r
+ else:\r
+ @property\r
+ def tb_next(self) -> Optional[TracebackType]: ...\r
+ # the rest are read-only even in 3.7\r
+ @property\r
+ def tb_frame(self) -> FrameType: ...\r
+ @property\r
+ def tb_lasti(self) -> int: ...\r
+ @property\r
+ def tb_lineno(self) -> int: ...\r
+\r
+class FrameType:\r
+ f_back = ... # type: FrameType\r
+ f_builtins = ... # type: Dict[str, Any]\r
+ f_code = ... # type: CodeType\r
+ f_globals = ... # type: Dict[str, Any]\r
+ f_lasti = ... # type: int\r
+ f_lineno = ... # type: int\r
+ f_locals = ... # type: Dict[str, Any]\r
+ f_trace = ... # type: Callable[[], None]\r
+ if sys.version_info >= (3, 7):\r
+ f_frace_lines: bool\r
+ f_trace_opcodes: bool\r
+\r
+ def clear(self) -> None: ...\r
+\r
+class GetSetDescriptorType:\r
+ __name__ = ... # type: str\r
+ __objclass__ = ... # type: type\r
+ def __get__(self, obj: Any, type: type = ...) -> Any: ...\r
+ def __set__(self, obj: Any) -> None: ...\r
+ def __delete__(self, obj: Any) -> None: ...\r
+class MemberDescriptorType:\r
+ __name__ = ... # type: str\r
+ __objclass__ = ... # type: type\r
+ def __get__(self, obj: Any, type: type = ...) -> Any: ...\r
+ def __set__(self, obj: Any) -> None: ...\r
+ def __delete__(self, obj: Any) -> None: ...\r
+\r
+def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ...\r
+def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ...) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ...\r
+\r
+# Actually a different type, but `property` is special and we want that too.\r
+DynamicClassAttribute = property\r
+\r
+def coroutine(f: Callable[..., Any]) -> CoroutineType: ...\r