diff --git a/third_party/2.7/six/__init__.pyi b/third_party/2.7/six/__init__.pyi new file mode 100644 index 000000000..60ba11759 --- /dev/null +++ b/third_party/2.7/six/__init__.pyi @@ -0,0 +1,90 @@ +# Stubs for six (Python 2.7) + +from __future__ import print_function + +from typing import ( + Any, AnyStr, Callable, Iterable, Mapping, Optional, + Pattern, Tuple, TypeVar, Union, overload, +) +import typing + +import unittest +import types + +_T = TypeVar('_T') +_K = TypeVar('_K') +_V = TypeVar('_V') + +# TODO make constant, then move this stub to 2and3 +# https://github.com/python/typeshed/issues/17 +PY2 = True +PY3 = False +PY34 = False + +string_types = basestring, +integer_types = (int, long) +class_types = (type, types.ClassType) +text_type = unicode +binary_type = str + +MAXSIZE = ... # type: int + +#def add_move +#def remove_move + +def advance_iterator(it: typing.Iterator[_T]) -> _T: ... +next = advance_iterator + +def callable(obj: object) -> bool: ... + +def get_unbound_function(unbound: types.MethodType) -> types.FunctionType: ... +def create_bound_method(func: types.FunctionType, obj: object) -> types.MethodType: ... +def create_unbound_method(func: types.FunctionType, cls: Union[type, types.ClassType]) -> types.MethodType: ... + +class Iterator: + def next(self) -> Any: ... + +def get_method_function(meth: types.MethodType) -> types.FunctionType: ... +def get_method_self(meth: types.MethodType) -> Optional[object]: ... +def get_function_closure(fun: types.FunctionType) -> Optional[Tuple[types._Cell, ...]]: ... +def get_function_code(fun: types.FunctionType) -> types.CodeType: ... +def get_function_defaults(fun: types.FunctionType) -> Optional[Tuple[Any, ...]]: ... +def get_function_globals(fun: types.FunctionType) -> Dict[str, Any]: ... + +def iterkeys(d: Mapping[_K, _V]) -> typing.Iterator[_K]: ... +def itervalues(d: Mapping[_K, _V]) -> typing.Iterator[_V]: ... +def iteritems(d: Mapping[_K, _V]) -> typing.Iterator[Tuple[_K, _V]]: ... +#def iterlists + +# TODO fix return types - python2 typing doesn't include KeysView etc yet. +def viewkeys(d: Mapping[_K, _V]) -> Iterable[_K]: ... +def viewvalues(d: Mapping[_K, _V]) -> Iterable[_V]: ... +def viewitems(d: Mapping[_K, _V]) -> Iterable[Tuple[_K, _V]]: ... + +def b(s: str) -> binary_type: ... +def u(s: str) -> text_type: ... +from __builtin__ import unichr as unichr +int2byte = chr +def byte2int(bs: binary_type) -> int: ... +def indexbytes(buf: binary_type, i: int) -> int: ... +def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... +from StringIO import StringIO as StringIO, StringIO as BytesIO + +def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: str = None) -> None: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, msg: str = None) -> Any: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ... +def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: str = None) -> None: ... + +def reraise(tp: type, value: Optional[BaseException], tb: types.TracebackType = None) -> None: ... +def exec_(_code_: Union[unicode, types.CodeType], _globs_: Dict[str, Any] = None, _locs_: Dict[str, Any] = None): ... +def raise_from(value: BaseException, from_value: BaseException) -> None: ... + +print_ = print + +from functools import wraps as wraps + +def with_metaclass(meta: type, *bases: type) -> type: ... +def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ... +def python_2_unicode_compatible(klass: _T) -> _T: ... diff --git a/third_party/3/six/__init__.pyi b/third_party/3/six/__init__.pyi new file mode 100644 index 000000000..0607cc18f --- /dev/null +++ b/third_party/3/six/__init__.pyi @@ -0,0 +1,103 @@ +# Stubs for six (Python 3.5) + +from __future__ import print_function + +from typing import ( + Any, + AnyStr, + Callable, + Dict, + ItemsView, + Iterable, + KeysView, + Mapping, + Optional, + Pattern, + Tuple, + TypeVar, + Union, + ValuesView, + overload, +) +import typing + +import unittest +import types + +_T = TypeVar('_T') +_K = TypeVar('_K') +_V = TypeVar('_V') + +# TODO make constant, then move this stub to 2and3 +# https://github.com/python/typeshed/issues/17 +PY2 = False +PY3 = True +PY34 = ... # type: bool + +string_types = str, +integer_types = int, +class_types = type, +text_type = str +binary_type = bytes + +MAXSIZE = ... # type: int + +#def add_move +#def remove_move + +from builtins import next as advance_iterator +next = advance_iterator + +def callable(obj: object) -> bool: ... + +def get_unbound_function(unbound: types.FunctionType) -> types.FunctionType: ... +def create_bound_method(func: types.FunctionType, obj: object) -> types.MethodType: ... +def create_unbound_method(func: types.FunctionType, cls: type) -> types.FunctionType: ... + +Iterator = object + +def get_method_function(meth: types.MethodType) -> types.FunctionType: ... +def get_method_self(meth: types.MethodType) -> Optional[object]: ... +def get_function_closure(fun: types.FunctionType) -> Optional[Tuple[types._Cell, ...]]: ... +def get_function_code(fun: types.FunctionType) -> types.CodeType: ... +def get_function_defaults(fun: types.FunctionType) -> Optional[Tuple[Any, ...]]: ... +def get_function_globals(fun: types.FunctionType) -> Dict[str, Any]: ... + +def iterkeys(d: Mapping[_K, _V]) -> typing.Iterator[_K]: ... +def itervalues(d: Mapping[_K, _V]) -> typing.Iterator[_V]: ... +def iteritems(d: Mapping[_K, _V]) -> typing.Iterator[Tuple[_K, _V]]: ... +#def iterlists + +def viewkeys(d: Mapping[_K, _V]) -> KeysView[_K]: ... +def viewvalues(d: Mapping[_K, _V]) -> ValuesView[_V]: ... +def viewitems(d: Mapping[_K, _V]) -> ItemsView[_K, _V]: ... + +def b(s: str) -> binary_type: ... +def u(s: str) -> text_type: ... + +unichr = chr +def int2byte(i: int) -> bytes: ... +def byte2int(bs: binary_type) -> int: ... +def indexbytes(buf: binary_type, i: int) -> int: ... +def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... +from io import StringIO as StringIO, BytesIO as BytesIO + +def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: str = None) -> None: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, msg: str = None) -> Any: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ... +def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: str = None) -> None: ... + +exec_ = exec + +def reraise(tp: type, value: Optional[BaseException], tb: types.TracebackType = None) -> None: ... +def raise_from(value: BaseException, from_value: BaseException) -> None: ... + +print_ = print + +from functools import wraps as wraps + +def with_metaclass(meta: type, *bases: type) -> type: ... +def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ... +def python_2_unicode_compatible(klass: _T) -> _T: ...