1from __future__ import print_function 2 3from typing import ( 4 Any, 5 AnyStr, 6 Callable, 7 Dict, 8 ItemsView, 9 Iterable, 10 KeysView, 11 Mapping, 12 NoReturn, 13 Optional, 14 Pattern, 15 Text, 16 Tuple, 17 Type, 18 TypeVar, 19 Union, 20 ValuesView, 21 overload, 22) 23import types 24import typing 25import unittest 26 27from io import StringIO as StringIO, BytesIO as BytesIO 28from builtins import next as next 29from functools import wraps as wraps 30from . import moves 31 32_T = TypeVar('_T') 33_K = TypeVar('_K') 34_V = TypeVar('_V') 35 36__version__: str 37 38# TODO make constant, then move this stub to 2and3 39# https://github.com/python/typeshed/issues/17 40PY2 = False 41PY3 = True 42PY34: bool 43 44string_types = str, 45integer_types = int, 46class_types = type, 47text_type = str 48binary_type = bytes 49 50MAXSIZE: int 51 52def callable(obj: object) -> bool: ... 53 54def get_unbound_function(unbound: types.FunctionType) -> types.FunctionType: ... 55def create_bound_method(func: types.FunctionType, obj: object) -> types.MethodType: ... 56def create_unbound_method(func: types.FunctionType, cls: type) -> types.FunctionType: ... 57 58Iterator = object 59 60def get_method_function(meth: types.MethodType) -> types.FunctionType: ... 61def get_method_self(meth: types.MethodType) -> Optional[object]: ... 62def get_function_closure(fun: types.FunctionType) -> Optional[Tuple[types._Cell, ...]]: ... 63def get_function_code(fun: types.FunctionType) -> types.CodeType: ... 64def get_function_defaults(fun: types.FunctionType) -> Optional[Tuple[Any, ...]]: ... 65def get_function_globals(fun: types.FunctionType) -> Dict[str, Any]: ... 66 67def iterkeys(d: Mapping[_K, _V]) -> typing.Iterator[_K]: ... 68def itervalues(d: Mapping[_K, _V]) -> typing.Iterator[_V]: ... 69def iteritems(d: Mapping[_K, _V]) -> typing.Iterator[Tuple[_K, _V]]: ... 70# def iterlists 71 72def viewkeys(d: Mapping[_K, _V]) -> KeysView[_K]: ... 73def viewvalues(d: Mapping[_K, _V]) -> ValuesView[_V]: ... 74def viewitems(d: Mapping[_K, _V]) -> ItemsView[_K, _V]: ... 75 76def b(s: str) -> binary_type: ... 77def u(s: str) -> text_type: ... 78 79unichr = chr 80def int2byte(i: int) -> bytes: ... 81def byte2int(bs: binary_type) -> int: ... 82def indexbytes(buf: binary_type, i: int) -> int: ... 83def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... 84 85def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: Optional[str] = ...) -> None: ... 86@overload 87def assertRaisesRegex(self: unittest.TestCase, msg: Optional[str] = ...) -> Any: ... 88@overload 89def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ... 90def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: Optional[str] = ...) -> None: ... 91 92exec_ = exec 93 94def reraise(tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = ...) -> NoReturn: ... 95def raise_from(value: Union[BaseException, Type[BaseException]], from_value: Optional[BaseException]) -> NoReturn: ... 96 97print_ = print 98 99def with_metaclass(meta: type, *bases: type) -> type: ... 100def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ... 101def ensure_binary(s: Union[bytes, Text], encoding: str = ..., errors: str = ...) -> bytes: ... 102def ensure_str(s: Union[bytes, Text], encoding: str = ..., errors: str = ...) -> str: ... 103def ensure_text(s: Union[bytes, Text], encoding: str = ..., errors: str = ...) -> Text: ... 104def python_2_unicode_compatible(klass: _T) -> _T: ... 105 106class _LazyDescriptor: 107 name: str 108 def __init__(self, name: str) -> None: ... 109 def __get__(self, obj: Optional[object], type: Optional[type] = ...) -> Any: ... 110 111class MovedModule(_LazyDescriptor): 112 mod: str 113 def __init__(self, name: str, old: str, new: Optional[str] = ...) -> None: ... 114 def __getattr__(self, attr: str) -> Any: ... 115 116class MovedAttribute(_LazyDescriptor): 117 mod: str 118 attr: str 119 def __init__(self, name: str, old_mod: str, new_mod: str, old_attr: Optional[str] = ..., new_attr: Optional[str] = ...) -> None: ... 120 121def add_move(move: Union[MovedModule, MovedAttribute]) -> None: ... 122def remove_move(name: str) -> None: ... 123