From 867851ad03bac37e7730b29e725c53e2e8fc448a Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 21 Oct 2018 20:59:11 +0200 Subject: [PATCH 1/9] Merge builtins.pyi from stdlib/2 and /3 --- stdlib/2/__builtin__.pyi | 1552 +++++++++++++++++++++++++------------- stdlib/2/builtins.pyi | 1552 +++++++++++++++++++++++++------------- stdlib/3/builtins.pyi | 1342 ++++++++++++++++++++++---------- 3 files changed, 2943 insertions(+), 1503 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 4dc1b434bd77..cda0a31616b3 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1,17 +1,19 @@ -# NB: __builtin__.pyi and builtins.pyi must remain consistent! -# Stubs for builtins (Python 2.7) - # True and False are deliberately omitted because they are keywords in # Python 3, and stub files conform to Python 3 syntax. from typing import ( - TypeVar, Iterator, Iterable, NoReturn, overload, - Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set, - AbstractSet, FrozenSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, - SupportsComplex, SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping, - MutableSet, ItemsView, KeysView, ValuesView, Optional, Container, Type + TypeVar, Iterator, Iterable, NoReturn, overload, Container, + Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic, + Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, + SupportsComplex, SupportsRound, IO, BinaryIO, Union, + ItemsView, KeysView, ValuesView, ByteString, Optional, AnyStr, Type, Text, ) -from abc import ABCMeta +from abc import abstractmethod, ABCMeta +from types import TracebackType, CodeType +import sys + +if sys.version_info >= (3,): + from typing import SupportsBytes _T = TypeVar('_T') _T_co = TypeVar('_T_co', covariant=True) @@ -28,8 +30,10 @@ _TT = TypeVar('_TT', bound='type') class object: __doc__ = ... # type: Optional[str] __dict__ = ... # type: Dict[str, Any] - __slots__ = ... # type: Union[str, unicode, Iterable[Union[str, unicode]]] + __slots__ = ... # type: Union[Text, Iterable[Text]] __module__ = ... # type: str + if sys.version_info >= (3, 6): + __annotations__ = ... # type: Dict[str, Any] @property def __class__(self: _T) -> Type[_T]: ... @@ -49,9 +53,15 @@ class object: def __sizeof__(self) -> int: ... def __reduce__(self) -> tuple: ... def __reduce_ex__(self, protocol: int) -> tuple: ... + if sys.version_info >= (3,): + def __dir__(self) -> Iterable[str]: ... + if sys.version_info >= (3, 6): + def __init_subclass__(cls) -> None: ... class staticmethod(object): # Special, only valid as a decorator. __func__ = ... # type: function + if sys.version_info >= (3,): + __isabstractmethod__ = ... # type: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... @@ -59,6 +69,8 @@ class staticmethod(object): # Special, only valid as a decorator. class classmethod(object): # Special, only valid as a decorator. __func__ = ... # type: function + if sys.version_info >= (3,): + __isabstractmethod__ = ... # type: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... @@ -68,40 +80,63 @@ class type(object): __bases__ = ... # type: Tuple[type, ...] __name__ = ... # type: str __module__ = ... # type: str + if sys.version_info >= (3,): + __qualname__ = ... # type: str + __dict__ = ... # type: Dict[str, Any] + __mro__ = ... # type: Tuple[type, ...] @overload def __init__(self, o: object) -> None: ... @overload def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... - # TODO: __new__ may have to be special and not a static method. @overload def __new__(cls, o: object) -> type: ... @overload def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... - - # Only new-style classes - __mro__ = ... # type: Tuple[type, ...] + def __subclasses__(self: _TT) -> List[_TT]: ... + if sys.version_info < (3,): + # Only new-style classes + __mro__ = ... # type: Tuple[type, ...] # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... - def __subclasses__(self: _TT) -> List[_TT]: ... def __instancecheck__(self, instance: Any) -> bool: ... def __subclasscheck__(self, subclass: type) -> bool: ... +class super(object): + if sys.version_info >= (3,): + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + @overload + def __init__(self) -> None: ... + else: + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + class int: @overload - def __init__(self, x: SupportsInt = ...) -> None: ... + def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ... @overload - def __init__(self, x: Union[str, unicode, bytearray], base: int = ...) -> None: ... + def __init__(self, x: Union[Text, bytes, bytearray], base: int) -> None: ... def bit_length(self) -> int: ... + if sys.version_info >= (3,): + def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ... + @classmethod + def from_bytes(cls, bytes: Sequence[int], byteorder: str, *, + signed: bool = ...) -> int: ... # TODO buffer object argument def __add__(self, x: int) -> int: ... def __sub__(self, x: int) -> int: ... def __mul__(self, x: int) -> int: ... def __floordiv__(self, x: int) -> int: ... - def __div__(self, x: int) -> int: ... + if sys.version_info < (3,): + def __div__(self, x: int) -> int: ... def __truediv__(self, x: int) -> float: ... def __mod__(self, x: int) -> int: ... def __divmod__(self, x: int) -> Tuple[int, int]: ... @@ -109,7 +144,8 @@ class int: def __rsub__(self, x: int) -> int: ... def __rmul__(self, x: int) -> int: ... def __rfloordiv__(self, x: int) -> int: ... - def __rdiv__(self, x: int) -> int: ... + if sys.version_info < (3,): + def __rdiv__(self, x: int) -> int: ... def __rtruediv__(self, x: int) -> float: ... def __rmod__(self, x: int) -> int: ... def __rdivmod__(self, x: int) -> Tuple[int, int]: ... @@ -128,6 +164,8 @@ class int: def __neg__(self) -> int: ... def __pos__(self) -> int: ... def __invert__(self) -> int: ... + if sys.version_info >= (3,): + def __round__(self, ndigits: Optional[int] = ...) -> int: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... @@ -141,11 +179,14 @@ class int: def __int__(self) -> int: ... def __abs__(self) -> int: ... def __hash__(self) -> int: ... - def __nonzero__(self) -> bool: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... def __index__(self) -> int: ... class float: - def __init__(self, x: Union[SupportsFloat, str, unicode, bytearray] = ...) -> None: ... + def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ... def as_integer_ratio(self) -> Tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @@ -156,7 +197,8 @@ class float: def __sub__(self, x: float) -> float: ... def __mul__(self, x: float) -> float: ... def __floordiv__(self, x: float) -> float: ... - def __div__(self, x: float) -> float: ... + if sys.version_info < (3,): + def __div__(self, x: float) -> float: ... def __truediv__(self, x: float) -> float: ... def __mod__(self, x: float) -> float: ... def __divmod__(self, x: float) -> Tuple[float, float]: ... @@ -165,11 +207,19 @@ class float: def __rsub__(self, x: float) -> float: ... def __rmul__(self, x: float) -> float: ... def __rfloordiv__(self, x: float) -> float: ... - def __rdiv__(self, x: float) -> float: ... + if sys.version_info < (3,): + def __rdiv__(self, x: float) -> float: ... def __rtruediv__(self, x: float) -> float: ... def __rmod__(self, x: float) -> float: ... def __rdivmod__(self, x: float) -> Tuple[float, float]: ... def __rpow__(self, x: float) -> float: ... + if sys.version_info >= (3,): + @overload + def __round__(self) -> int: ... + @overload + def __round__(self, ndigits: None) -> int: ... + @overload + def __round__(self, ndigits: int) -> float: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... @@ -185,7 +235,10 @@ class float: def __float__(self) -> float: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... - def __nonzero__(self) -> bool: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... class complex: @overload @@ -206,13 +259,15 @@ class complex: def __sub__(self, x: complex) -> complex: ... def __mul__(self, x: complex) -> complex: ... def __pow__(self, x: complex) -> complex: ... - def __div__(self, x: complex) -> complex: ... + if sys.version_info < (3,): + def __div__(self, x: complex) -> complex: ... def __truediv__(self, x: complex) -> complex: ... def __radd__(self, x: complex) -> complex: ... def __rsub__(self, x: complex) -> complex: ... def __rmul__(self, x: complex) -> complex: ... def __rpow__(self, x: complex) -> complex: ... - def __rdiv__(self, x: complex) -> complex: ... + if sys.version_info < (3,): + def __rdiv__(self, x: complex) -> complex: ... def __rtruediv__(self, x: complex) -> complex: ... def __eq__(self, x: object) -> bool: ... @@ -220,206 +275,365 @@ class complex: def __neg__(self) -> complex: ... def __pos__(self) -> complex: ... - def __complex__(self) -> complex: ... def __str__(self) -> str: ... + def __complex__(self) -> complex: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... - def __nonzero__(self) -> bool: ... - -class super(object): - @overload - def __init__(self, t: Any, obj: Any) -> None: ... - @overload - def __init__(self, t: Any) -> None: ... - -class basestring(metaclass=ABCMeta): ... - -class unicode(basestring, Sequence[unicode]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, o: object) -> None: ... - @overload - def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... - def capitalize(self) -> unicode: ... - def center(self, width: int, fillchar: unicode = ...) -> unicode: ... - def count(self, x: unicode) -> int: ... - def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... - def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... - def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., - end: int = ...) -> bool: ... - def expandtabs(self, tabsize: int = ...) -> unicode: ... - def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> unicode: ... - def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... - def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def isalnum(self) -> bool: ... - def isalpha(self) -> bool: ... - def isdecimal(self) -> bool: ... - def isdigit(self) -> bool: ... - def isidentifier(self) -> bool: ... - def islower(self) -> bool: ... - def isnumeric(self) -> bool: ... - def isprintable(self) -> bool: ... - def isspace(self) -> bool: ... - def istitle(self) -> bool: ... - def isupper(self) -> bool: ... - def join(self, iterable: Iterable[unicode]) -> unicode: ... - def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... - def lower(self) -> unicode: ... - def lstrip(self, chars: unicode = ...) -> unicode: ... - def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... - def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... - def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... - def rstrip(self, chars: unicode = ...) -> unicode: ... - def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... - def splitlines(self, keepends: bool = ...) -> List[unicode]: ... - def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., - end: int = ...) -> bool: ... - def strip(self, chars: unicode = ...) -> unicode: ... - def swapcase(self) -> unicode: ... - def title(self) -> unicode: ... - def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... - def upper(self) -> unicode: ... - def zfill(self, width: int) -> unicode: ... - - @overload - def __getitem__(self, i: int) -> unicode: ... - @overload - def __getitem__(self, s: slice) -> unicode: ... - def __getslice__(self, start: int, stop: int) -> unicode: ... - def __add__(self, s: unicode) -> unicode: ... - def __mul__(self, n: int) -> unicode: ... - def __rmul__(self, n: int) -> unicode: ... - def __mod__(self, x: Any) -> unicode: ... - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: unicode) -> bool: ... - def __le__(self, x: unicode) -> bool: ... - def __gt__(self, x: unicode) -> bool: ... - def __ge__(self, x: unicode) -> bool: ... - - def __len__(self) -> int: ... - def __contains__(self, s: object) -> bool: ... - def __iter__(self) -> Iterator[unicode]: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... + +if sys.version_info >= (3,): + _str_base = object +else: + class basestring(metaclass=ABCMeta): ... + + class unicode(basestring, Sequence[unicode]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... + def capitalize(self) -> unicode: ... + def center(self, width: int, fillchar: unicode = ...) -> unicode: ... + def count(self, x: unicode) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> unicode: ... + def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> unicode: ... + def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... + def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def isidentifier(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[unicode]) -> unicode: ... + def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def lower(self) -> unicode: ... + def lstrip(self, chars: unicode = ...) -> unicode: ... + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... + def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def rstrip(self, chars: unicode = ...) -> unicode: ... + def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[unicode]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def strip(self, chars: unicode = ...) -> unicode: ... + def swapcase(self) -> unicode: ... + def title(self) -> unicode: ... + def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... + def upper(self) -> unicode: ... + def zfill(self, width: int) -> unicode: ... + + @overload + def __getitem__(self, i: int) -> unicode: ... + @overload + def __getitem__(self, s: slice) -> unicode: ... + def __getslice__(self, start: int, stop: int) -> unicode: ... + def __add__(self, s: unicode) -> unicode: ... + def __mul__(self, n: int) -> unicode: ... + def __rmul__(self, n: int) -> unicode: ... + def __mod__(self, x: Any) -> unicode: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: unicode) -> bool: ... + def __le__(self, x: unicode) -> bool: ... + def __gt__(self, x: unicode) -> bool: ... + def __ge__(self, x: unicode) -> bool: ... + + def __len__(self) -> int: ... + def __contains__(self, s: object) -> bool: ... + def __iter__(self) -> Iterator[unicode]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + + _str_base = basestring + +class str(Sequence[str], _str_base): + if sys.version_info >= (3,): + @overload + def __init__(self, o: object = ...) -> None: ... + @overload + def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ... + else: + def __init__(self, o: object = ...) -> None: ... -class str(basestring, Sequence[str]): - def __init__(self, object: object = ...) -> None: ... def capitalize(self) -> str: ... + if sys.version_info >= (3, 3): + def casefold(self) -> str: ... def center(self, width: int, fillchar: str = ...) -> str: ... - def count(self, x: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... - def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... - def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + def count(self, x: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info < (3,): + def decode(self, encoding: Text = ..., errors: Text = ...) -> unicode: ... + def encode(self, encoding: Text = ..., errors: Text = ...) -> bytes: ... + if sys.version_info >= (3,): + def endswith(self, suffix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + else: + def endswith(self, suffix: Union[Text, Tuple[Text, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> str: ... - def find(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def format(self, *args: Any, **kwargs: Any) -> str: ... - def index(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def format_map(self, map: Mapping[str, Any]) -> str: ... + def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... + if sys.version_info >= (3,): + def isdecimal(self) -> bool: ... def isdigit(self) -> bool: ... + if sys.version_info >= (3,): + def isidentifier(self) -> bool: ... def islower(self) -> bool: ... + if sys.version_info >= (3,): + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... + if sys.version_info >= (3,): + def join(self, iterable: Iterable[str]) -> str: ... + else: + def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... def ljust(self, width: int, fillchar: str = ...) -> str: ... def lower(self) -> str: ... - @overload - def lstrip(self, chars: str = ...) -> str: ... - @overload - def lstrip(self, chars: unicode) -> unicode: ... - @overload - def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... - @overload - def partition(self, sep: str) -> Tuple[str, str, str]: ... - @overload - def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... - def rfind(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def rindex(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def lstrip(self, chars: Optional[str] = ...) -> str: ... + def partition(self, sep: str) -> Tuple[str, str, str]: ... + def replace(self, old: str, new: str, count: int = ...) -> str: ... + else: + @overload + def lstrip(self, chars: str = ...) -> str: ... + @overload + def lstrip(self, chars: unicode) -> unicode: ... + @overload + def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def partition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... + def rfind(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def rjust(self, width: int, fillchar: str = ...) -> str: ... - @overload - def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... - @overload - def rpartition(self, sep: str) -> Tuple[str, str, str]: ... - @overload - def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - @overload - def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - @overload - def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... - @overload - def rstrip(self, chars: str = ...) -> str: ... - @overload - def rstrip(self, chars: unicode) -> unicode: ... - @overload - def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - @overload - def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + if sys.version_info >= (3,): + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + def rstrip(self, chars: Optional[str] = ...) -> str: ... + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + else: + @overload + def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + @overload + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + @overload + def rstrip(self, chars: str = ...) -> str: ... + @overload + def rstrip(self, chars: unicode) -> unicode: ... + @overload + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... def splitlines(self, keepends: bool = ...) -> List[str]: ... - def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... - @overload - def strip(self, chars: str = ...) -> str: ... - @overload - def strip(self, chars: unicode) -> unicode: ... + if sys.version_info >= (3,): + def startswith(self, prefix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + def strip(self, chars: Optional[str] = ...) -> str: ... + else: + def startswith(self, prefix: Union[Text, Tuple[Text, ...]]) -> bool: ... + @overload + def strip(self, chars: str = ...) -> str: ... + @overload + def strip(self, chars: unicode) -> unicode: ... def swapcase(self) -> str: ... def title(self) -> str: ... - def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... + if sys.version_info >= (3,): + def translate(self, table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ... + else: + def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... def upper(self) -> str: ... def zfill(self, width: int) -> str: ... - - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[str]: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... - @overload - def __getitem__(self, i: int) -> str: ... - @overload - def __getitem__(self, s: slice) -> str: ... - def __getslice__(self, start: int, stop: int) -> str: ... - def __add__(self, s: AnyStr) -> AnyStr: ... - def __mul__(self, n: int) -> str: ... - def __rmul__(self, n: int) -> str: ... + if sys.version_info >= (3,): + @staticmethod + @overload + def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... + @staticmethod + @overload + def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... + + if sys.version_info >= (3,): + def __add__(self, s: str) -> str: ... + else: + def __add__(self, s: AnyStr) -> AnyStr: ... def __contains__(self, o: object) -> bool: ... def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: unicode) -> bool: ... - def __le__(self, x: unicode) -> bool: ... - def __gt__(self, x: unicode) -> bool: ... - def __ge__(self, x: unicode) -> bool: ... + def __ge__(self, x: Text) -> bool: ... + def __getitem__(self, i: Union[int, slice]) -> str: ... + def __gt__(self, x: Text) -> bool: ... + def __hash__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + def __le__(self, x: Text) -> bool: ... + def __len__(self) -> int: ... + def __lt__(self, x: Text) -> bool: ... def __mod__(self, x: Any) -> str: ... + def __mul__(self, n: int) -> str: ... + def __ne__(self, x: object) -> bool: ... + def __repr__(self) -> str: ... + def __rmul__(self, n: int) -> str: ... + def __str__(self) -> str: ... -class bytearray(MutableSequence[int]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, x: Union[Iterable[int], str]) -> None: ... - @overload - def __init__(self, x: unicode, encoding: unicode, - errors: unicode = ...) -> None: ... - @overload - def __init__(self, length: int) -> None: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> str: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + +if sys.version_info >= (3,): + class bytes(ByteString): + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str, encoding: str, + errors: str = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: SupportsBytes) -> None: ... + def capitalize(self) -> bytes: ... + def center(self, width: int, fillchar: bytes = ...) -> bytes: ... + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def decode(self, encoding: str = ..., errors: str = ...) -> str: ... + def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> bytes: ... + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytes: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def lower(self) -> bytes: ... + def lstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def replace(self, old: bytes, new: bytes, count: int = ...) -> bytes: ... + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def rstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def splitlines(self, keepends: bool = ...) -> List[bytes]: ... + def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def strip(self, chars: Optional[bytes] = ...) -> bytes: ... + def swapcase(self) -> bytes: ... + def title(self) -> bytes: ... + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ... + def upper(self) -> bytes: ... + def zfill(self, width: int) -> bytes: ... + @classmethod + def fromhex(cls, s: str) -> bytes: ... + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> bytes: ... + def __add__(self, s: bytes) -> bytes: ... + def __mul__(self, n: int) -> bytes: ... + def __rmul__(self, n: int) -> bytes: ... + if sys.version_info >= (3, 5): + def __mod__(self, value: Any) -> bytes: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: bytes) -> bool: ... + def __le__(self, x: bytes) -> bool: ... + def __gt__(self, x: bytes) -> bool: ... + def __ge__(self, x: bytes) -> bool: ... +else: + bytes = str + +class bytearray(MutableSequence[int], ByteString): + if sys.version_info >= (3,): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + else: + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str) -> None: ... + @overload + def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... def capitalize(self) -> bytearray: ... - def center(self, width: int, fillchar: str = ...) -> bytearray: ... - def count(self, x: str) -> int: ... - def decode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... - def endswith(self, suffix: Union[str, Tuple[str, ...]]) -> bool: ... + def center(self, width: int, fillchar: bytes = ...) -> bytearray: ... + if sys.version_info >= (3,): + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def copy(self) -> bytearray: ... + else: + def count(self, x: str) -> int: ... + def decode(self, encoding: Text = ..., errors: Text = ...) -> str: ... + def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytearray: ... - def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... + if sys.version_info >= (3,): + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + else: + def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... def insert(self, index: int, object: int) -> None: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -428,29 +642,43 @@ class bytearray(MutableSequence[int]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[str]) -> bytearray: ... - def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... + if sys.version_info >= (3,): + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytearray: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + else: + def join(self, iterable: Iterable[str]) -> bytearray: ... + def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... def lower(self) -> bytearray: ... - def lstrip(self, chars: str = ...) -> bytearray: ... - def partition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... - def replace(self, old: str, new: str, count: int = ...) -> bytearray: ... - def rfind(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def rindex(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def rjust(self, width: int, fillchar: str = ...) -> bytearray: ... - def rpartition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... - def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... - def rstrip(self, chars: str = ...) -> bytearray: ... - def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def lstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... + def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... + def replace(self, old: bytes, new: bytes, count: int = ...) -> bytearray: ... + if sys.version_info >= (3,): + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + else: + def rfind(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def rstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... - def startswith(self, prefix: Union[str, Tuple[str, ...]]) -> bool: ... - def strip(self, chars: str = ...) -> bytearray: ... + def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def strip(self, chars: Optional[bytes] = ...) -> bytearray: ... def swapcase(self) -> bytearray: ... def title(self) -> bytearray: ... - def translate(self, table: str) -> bytearray: ... + if sys.version_info >= (3,): + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ... + else: + def translate(self, table: str) -> bytearray: ... def upper(self) -> bytearray: ... def zfill(self, width: int) -> bytearray: ... @staticmethod - def fromhex(x: str) -> bytearray: ... + def fromhex(s: str) -> bytearray: ... + if sys.version_info >= (3,): + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ... @@ -463,23 +691,74 @@ class bytearray(MutableSequence[int]): def __getitem__(self, i: int) -> int: ... @overload def __getitem__(self, s: slice) -> bytearray: ... - def __getslice__(self, start: int, stop: int) -> bytearray: ... @overload def __setitem__(self, i: int, x: int) -> None: ... @overload - def __setitem__(self, s: slice, x: Union[Iterable[int], str]) -> None: ... - def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... + def __setitem__(self, s: slice, x: Union[Iterable[int], bytes]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... - def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, s: str) -> bytearray: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> bytearray: ... + def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + def __add__(self, s: bytes) -> bytearray: ... + if sys.version_info >= (3,): + def __iadd__(self, s: Iterable[int]) -> bytearray: ... def __mul__(self, n: int) -> bytearray: ... + if sys.version_info >= (3,): + def __rmul__(self, n: int) -> bytearray: ... + def __imul__(self, n: int) -> bytearray: ... + if sys.version_info >= (3, 5): + def __mod__(self, value: Any) -> bytes: ... def __contains__(self, o: object) -> bool: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: str) -> bool: ... - def __le__(self, x: str) -> bool: ... - def __gt__(self, x: str) -> bool: ... - def __ge__(self, x: str) -> bool: ... + def __lt__(self, x: bytes) -> bool: ... + def __le__(self, x: bytes) -> bool: ... + def __gt__(self, x: bytes) -> bool: ... + def __ge__(self, x: bytes) -> bool: ... + +if sys.version_info >= (3,): + _mv_container_type = int +else: + _mv_container_type = str + +class memoryview(Sized, Container[_mv_container_type]): + format = ... # type: str + itemsize = ... # type: int + shape = ... # type: Optional[Tuple[int, ...]] + strides = ... # type: Optional[Tuple[int, ...]] + suboffsets = ... # type: Optional[Tuple[int, ...]] + readonly = ... # type: bool + ndim = ... # type: int + + if sys.version_info >= (3,): + def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... + def __enter__(self) -> memoryview: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ... + else: + def __init__(self, obj: Union[bytes, bytearray, buffer, memoryview]) -> None: ... + + @overload + def __getitem__(self, i: int) -> _mv_container_type: ... + @overload + def __getitem__(self, s: slice) -> memoryview: ... + + def __contains__(self, x: object) -> bool: ... + def __iter__(self) -> Iterator[_mv_container_type]: ... + def __len__(self) -> int: ... + + @overload + def __setitem__(self, i: int, o: bytes) -> None: ... + @overload + def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... + @overload + def __setitem__(self, s: slice, o: memoryview) -> None: ... + + def tobytes(self) -> bytes: ... + def tolist(self) -> List[int]: ... + + if sys.version_info >= (3, 5): + def hex(self) -> str: ... class bool(int): def __init__(self, o: object = ...) -> None: ... @@ -535,18 +814,28 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... - def index(self, x: Any) -> int: ... + if sys.version_info >= (3, 5): + def index(self, x: Any, start: int = ..., end: int = ...) -> int: ... + else: + def index(self, x: Any) -> int: ... class function: - # TODO name of the class (corresponds to Python 'function' class) + # TODO not defined in builtins! __name__ = ... # type: str __module__ = ... # type: str + if sys.version_info >= (3,): + __qualname__ = ... # type: str + __code__ = ... # type: CodeType + __annotations__ = ... # type: Dict[str, Any] class list(MutableSequence[_T], Generic[_T]): @overload def __init__(self) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... + if sys.version_info >= (3,): + def clear(self) -> None: ... + def copy(self) -> List[_T]: ... def append(self, object: _T) -> None: ... def extend(self, iterable: Iterable[_T]) -> None: ... def pop(self, index: int = ...) -> _T: ... @@ -555,7 +844,10 @@ class list(MutableSequence[_T], Generic[_T]): def insert(self, index: int, object: _T) -> None: ... def remove(self, object: _T) -> None: ... def reverse(self) -> None: ... - def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... + if sys.version_info >= (3,): + def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ... + else: + def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... @@ -565,18 +857,21 @@ class list(MutableSequence[_T], Generic[_T]): def __getitem__(self, i: int) -> _T: ... @overload def __getitem__(self, s: slice) -> List[_T]: ... - def __getslice__(self, start: int, stop: int) -> List[_T]: ... @overload def __setitem__(self, i: int, o: _T) -> None: ... @overload def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... - def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... - def __delslice__(self, start: int, stop: int) -> None: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> List[_T]: ... + def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self, x: List[_T]) -> List[_T]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... + if sys.version_info >= (3,): + def __imul__(self, n: int) -> List[_T]: ... def __contains__(self, o: object) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... def __gt__(self, x: List[_T]) -> bool: ... @@ -596,29 +891,35 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... - def has_key(self, k: _KT) -> bool: ... + if sys.version_info < (3,): + def has_key(self, k: _KT) -> bool: ... def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... def popitem(self) -> Tuple[_KT, _VT]: ... - def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... + def setdefault(self, k: _KT, default: Optional[_VT] = ...) -> _VT: ... @overload def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... @overload def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... @overload def update(self, **kwargs: _VT) -> None: ... - def iterkeys(self) -> Iterator[_KT]: ... - def itervalues(self) -> Iterator[_VT]: ... - def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... - def viewkeys(self) -> KeysView[_KT]: ... - def viewvalues(self) -> ValuesView[_VT]: ... - def viewitems(self) -> ItemsView[_KT, _VT]: ... + if sys.version_info >= (3,): + def keys(self) -> KeysView[_KT]: ... + def values(self) -> ValuesView[_VT]: ... + def items(self) -> ItemsView[_KT, _VT]: ... + else: + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def viewkeys(self) -> KeysView[_KT]: ... + def viewvalues(self) -> ValuesView[_VT]: ... + def viewitems(self) -> ItemsView[_KT, _VT]: ... @staticmethod @overload - def fromkeys(seq: Sequence[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) + def fromkeys(seq: Iterable[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) @staticmethod @overload - def fromkeys(seq: Sequence[_T], value: _S) -> Dict[_T, _S]: ... + def fromkeys(seq: Iterable[_T], value: _S) -> Dict[_T, _S]: ... def __len__(self) -> int: ... def __getitem__(self, k: _KT) -> _VT: ... def __setitem__(self, k: _KT, v: _VT) -> None: ... @@ -636,9 +937,9 @@ class set(MutableSet[_T], Generic[_T]): def discard(self, element: _T) -> None: ... def intersection(self, *s: Iterable[Any]) -> Set[_T]: ... def intersection_update(self, *s: Iterable[Any]) -> None: ... - def isdisjoint(self, s: Iterable[object]) -> bool: ... - def issubset(self, s: Iterable[object]) -> bool: ... - def issuperset(self, s: Iterable[object]) -> bool: ... + def isdisjoint(self, s: Iterable[Any]) -> bool: ... + def issubset(self, s: Iterable[Any]) -> bool: ... + def issuperset(self, s: Iterable[Any]) -> bool: ... def pop(self) -> _T: ... def remove(self, element: _T) -> None: ... def symmetric_difference(self, s: Iterable[_T]) -> Set[_T]: ... @@ -663,10 +964,7 @@ class set(MutableSet[_T], Generic[_T]): def __gt__(self, s: AbstractSet[object]) -> bool: ... class frozenset(AbstractSet[_T], Generic[_T]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, iterable: Iterable[_T]) -> None: ... + def __init__(self, iterable: Iterable[_T] = ...) -> None: ... def copy(self) -> FrozenSet[_T]: ... def difference(self, *s: Iterable[object]) -> FrozenSet[_T]: ... def intersection(self, *s: Iterable[object]) -> FrozenSet[_T]: ... @@ -691,23 +989,48 @@ class frozenset(AbstractSet[_T], Generic[_T]): class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... def __iter__(self) -> Iterator[Tuple[int, _T]]: ... - def next(self) -> Tuple[int, _T]: ... + if sys.version_info >= (3,): + def __next__(self) -> Tuple[int, _T]: ... + else: + def next(self) -> Tuple[int, _T]: ... # TODO __getattribute__ -class xrange(Sized, Iterable[int], Reversible[int]): - @overload - def __init__(self, stop: int) -> None: ... - @overload - def __init__(self, start: int, stop: int, step: int = ...) -> None: ... - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[int]: ... - def __getitem__(self, i: int) -> int: ... - def __reversed__(self) -> Iterator[int]: ... +if sys.version_info >= (3,): + class range(Sequence[int]): + start = ... # type: int + stop = ... # type: int + step = ... # type: int + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def count(self, value: int) -> int: ... + def index(self, value: int, start: int = ..., stop: Optional[int] = ...) -> int: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[int]: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> range: ... + def __repr__(self) -> str: ... + def __reversed__(self) -> Iterator[int]: ... +else: + class xrange(Sized, Iterable[int], Reversible[int]): + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __getitem__(self, i: int) -> int: ... + def __reversed__(self) -> Iterator[int]: ... class property(object): def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., fset: Optional[Callable[[Any, Any], None]] = ..., - fdel: Optional[Callable[[Any], None]] = ..., doc: Optional[str] = ...) -> None: ... + fdel: Optional[Callable[[Any], None]] = ..., + doc: Optional[str] = ...) -> None: ... def getter(self, fget: Callable[[Any], Any]) -> property: ... def setter(self, fset: Callable[[Any, Any], None]) -> property: ... def deleter(self, fdel: Callable[[Any], None]) -> property: ... @@ -718,49 +1041,84 @@ class property(object): def fset(self, value: Any) -> None: ... def fdel(self) -> None: ... -long = int -bytes = str +if sys.version_info < (3,): + long = int NotImplemented = ... # type: Any def abs(n: SupportsAbs[_T]) -> _T: ... def all(i: Iterable[object]) -> bool: ... def any(i: Iterable[object]) -> bool: ... +if sys.version_info < (3,): + def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... +if sys.version_info >= (3,): + def ascii(o: object) -> str: ... def bin(number: int) -> str: ... +if sys.version_info >= (3, 7): + def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(o: object) -> bool: ... def chr(code: int) -> str: ... -def compile(source: Any, filename: unicode, mode: str, flags: int = ..., - dont_inherit: int = ...) -> Any: ... -def delattr(o: Any, name: unicode) -> None: ... +if sys.version_info < (3,): + def cmp(x: Any, y: Any) -> int: ... + _N1 = TypeVar('_N1', bool, int, float, complex) + def coerce(x: _N1, y: _N1) -> Tuple[_N1, _N1]: ... +if sys.version_info >= (3, 6): + # This class is to be exported as PathLike from os, + # but we define it here as _PathLike to avoid import cycle issues. + # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 + class _PathLike(Generic[AnyStr]): + def __fspath__(self) -> AnyStr: ... + def compile(source: Any, filename: Union[str, bytes, _PathLike], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... +else: + def compile(source: Any, filename: Union[str, bytes], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... +if sys.version_info >= (3,): + def copyright() -> None: ... + def credits() -> None: ... +def delattr(o: Any, name: Text) -> None: ... def dir(o: object = ...) -> List[str]: ... -@overload -def divmod(a: int, b: int) -> Tuple[int, int]: ... -@overload -def divmod(a: float, b: float) -> Tuple[float, float]: ... +_N2 = TypeVar('_N2', int, float) +def divmod(a: _N2, b: _N2) -> Tuple[_N2, _N2]: ... +def eval(source: Union[Text, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +if sys.version_info >= (3,): + def exec(object: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +else: + def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... def exit(code: Any = ...) -> NoReturn: ... -@overload -def filter(__function: Callable[[AnyStr], Any], # type: ignore - __iterable: AnyStr) -> AnyStr: ... -@overload -def filter(__function: None, # type: ignore - __iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ... -@overload -def filter(__function: Callable[[_T], Any], # type: ignore - __iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ... -@overload -def filter(__function: None, - __iterable: Iterable[Optional[_T]]) -> List[_T]: ... -@overload -def filter(__function: Callable[[_T], Any], - __iterable: Iterable[_T]) -> List[_T]: ... +if sys.version_info >= (3,): + @overload + def filter(__function: None, __iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... + @overload + def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Iterator[_T]: ... +else: + @overload + def filter(__function: Callable[[AnyStr], Any], # type: ignore + __iterable: AnyStr) -> AnyStr: ... + @overload + def filter(__function: None, # type: ignore + __iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ... + @overload + def filter(__function: Callable[[_T], Any], # type: ignore + __iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ... + @overload + def filter(__function: None, + __iterable: Iterable[Optional[_T]]) -> List[_T]: ... + @overload + def filter(__function: Callable[[_T], Any], + __iterable: Iterable[_T]) -> List[_T]: ... def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode -def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ... -def hasattr(o: Any, name: unicode) -> bool: ... +def getattr(o: Any, name: Text, default: Any = ...) -> Any: ... +def globals() -> Dict[str, Any]: ... +def hasattr(o: Any, name: Text) -> bool: ... def hash(o: object) -> int: ... +if sys.version_info >= (3,): + def help(*args: Any, **kwds: Any) -> None: ... def hex(i: int) -> str: ... # TODO __index__ def id(o: object) -> int: ... -def input(prompt: Any = ...) -> Any: ... -def intern(string: str) -> str: ... +if sys.version_info >= (3,): + def input(prompt: Any = ...) -> str: ... +else: + def input(prompt: Any = ...) -> Any: ... + def intern(string: str) -> str: ... @overload def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... @overload @@ -768,218 +1126,287 @@ def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ... def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... def issubclass(cls: type, classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... def len(o: Sized) -> int: ... -@overload -def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... -@overload -def map(func: None, - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -@overload -def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3, _T4], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> List[_S]: ... -@overload -def map(func: Callable[..., _S], - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[_S]: ... -@overload -def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +if sys.version_info >= (3,): + def license() -> None: ... +def locals() -> Dict[str, Any]: ... +if sys.version_info >= (3,): + @overload + def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> Iterator[_S]: ... + @overload + def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[_S]: ... +else: + @overload + def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... + @overload + def map(func: None, + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... + @overload + def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[_S]: ... + @overload + def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[_S]: ... +if sys.version_info >= (3,): + @overload + def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +else: + @overload + def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +if sys.version_info >= (3,): + @overload + def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +else: + @overload + def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... @overload def next(i: Iterator[_T]) -> _T: ... @overload def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... def oct(i: int) -> str: ... # TODO __index__ + +if sys.version_info >= (3, 6): + def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... +elif sys.version_info >= (3,): + def open(file: Union[str, bytes, int], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... +else: + def open(file: Union[unicode, int], mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... + +def ord(c: Union[str, bytes]) -> int: ... +if sys.version_info >= (3,): + def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[str]] = ..., flush: bool = ...) -> None: ... +else: + # This is only available after from __future__ import print_function. + def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[Any]] = ...) -> None: ... @overload -def open(file: str, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... -@overload -def open(file: unicode, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... -@overload -def open(file: int, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... -def ord(c: unicode) -> int: ... -# This is only available after from __future__ import print_function. -def print(*values: Any, sep: unicode = ..., end: unicode = ..., - file: IO[Any] = ...) -> None: ... -@overload -def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y. +def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y @overload def pow(x: int, y: int, z: int) -> Any: ... @overload def pow(x: float, y: float) -> float: ... @overload def pow(x: float, y: float, z: float) -> float: ... -def quit(code: int = ...) -> None: ... -def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... -def raw_input(prompt: Any = ...) -> str: ... - -@overload -def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... -@overload -def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... - -def reload(module: Any) -> Any: ... +def quit(code: Optional[int] = ...) -> None: ... +if sys.version_info < (3,): + def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... + def raw_input(prompt: Any = ...) -> str: ... + @overload + def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... + @overload + def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... + def reload(module: Any) -> Any: ... @overload def reversed(object: Sequence[_T]) -> Iterator[_T]: ... @overload def reversed(object: Reversible[_T]) -> Iterator[_T]: ... def repr(o: object) -> str: ... -@overload -def round(number: float) -> float: ... -@overload -def round(number: float, ndigits: int) -> float: ... # Always return a float if given ndigits. -@overload -def round(number: SupportsRound[_T]) -> _T: ... -@overload -def round(number: SupportsRound[_T], ndigits: int) -> _T: ... -def setattr(object: Any, name: unicode, value: Any) -> None: ... -def sorted(iterable: Iterable[_T], *, - cmp: Callable[[_T, _T], int] = ..., - key: Callable[[_T], Any] = ..., - reverse: bool = ...) -> List[_T]: ... +if sys.version_info >= (3,): + @overload + def round(number: float) -> int: ... + @overload + def round(number: float, ndigits: None) -> int: ... + @overload + def round(number: float, ndigits: int) -> float: ... + @overload + def round(number: SupportsRound[_T]) -> int: ... + @overload + def round(number: SupportsRound[_T], ndigits: None) -> int: ... # type: ignore + @overload + def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +else: + @overload + def round(number: float) -> float: ... + @overload + def round(number: float, ndigits: int) -> float: ... + @overload + def round(number: SupportsRound[_T]) -> _T: ... + @overload + def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +def setattr(object: Any, name: Text, value: Any) -> None: ... +if sys.version_info >= (3,): + def sorted(iterable: Iterable[_T], *, + key: Optional[Callable[[_T], Any]] = ..., + reverse: bool = ...) -> List[_T]: ... +else: + def sorted(iterable: Iterable[_T], *, + cmp: Callable[[_T, _T], int] = ..., + key: Callable[[_T], Any] = ..., + reverse: bool = ...) -> List[_T]: ... @overload def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... @overload def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... -def unichr(i: int) -> unicode: ... +if sys.version_info < (3,): + def unichr(i: int) -> unicode: ... def vars(object: Any = ...) -> Dict[str, Any]: ... -@overload -def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... -@overload -def zip(iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, - _T3, _T4]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, - _T3, _T4, _T5]]: ... -@overload -def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], - iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -def __import__(name: unicode, - globals: Dict[str, Any] = ..., - locals: Dict[str, Any] = ..., +if sys.version_info >= (3,): + @overload + def zip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... + @overload + def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... +else: + @overload + def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... + @overload + def zip(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, + _T3, _T4]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... + @overload + def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... +def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., fromlist: List[str] = ..., level: int = ...) -> Any: ... -def globals() -> Dict[str, Any]: ... -def locals() -> Dict[str, Any]: ... - # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. class ellipsis: ... Ellipsis = ... # type: ellipsis -# TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. -_AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) - -class buffer(Sized): - def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... - def __add__(self, other: _AnyBuffer) -> str: ... - def __cmp__(self, other: _AnyBuffer) -> bool: ... - def __getitem__(self, key: Union[int, slice]) -> str: ... - def __getslice__(self, i: int, j: int) -> str: ... - def __len__(self) -> int: ... - def __mul__(self, x: int) -> str: ... - -class memoryview(Sized, Container[bytes]): - format = ... # type: str - itemsize = ... # type: int - shape = ... # type: Optional[Tuple[int, ...]] - strides = ... # type: Optional[Tuple[int, ...]] - suboffsets = ... # type: Optional[Tuple[int, ...]] - readonly = ... # type: bool - ndim = ... # type: int - - def __init__(self, obj: Union[str, bytearray, buffer, memoryview]) -> None: ... - - @overload - def __getitem__(self, i: int) -> bytes: ... - @overload - def __getitem__(self, s: slice) -> memoryview: ... - - def __contains__(self, x: object) -> bool: ... - def __iter__(self) -> Iterator[bytes]: ... - def __len__(self) -> int: ... - - @overload - def __setitem__(self, i: int, o: bytes) -> None: ... - @overload - def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... - @overload - def __setitem__(self, s: slice, o: memoryview) -> None: ... +if sys.version_info < (3,): + # TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. + _AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) - def tobytes(self) -> bytes: ... - def tolist(self) -> List[int]: ... + class buffer(Sized): + def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... + def __add__(self, other: _AnyBuffer) -> str: ... + def __cmp__(self, other: _AnyBuffer) -> bool: ... + def __getitem__(self, key: Union[int, slice]) -> str: ... + def __getslice__(self, i: int, j: int) -> str: ... + def __len__(self) -> int: ... + def __mul__(self, x: int) -> str: ... class BaseException(object): args = ... # type: Tuple[Any, ...] - message = ... # type: Any + if sys.version_info < (3,): + message = ... # type: Any + if sys.version_info >= (3,): + __cause__ = ... # type: Optional[BaseException] + __context__ = ... # type: Optional[BaseException] + __traceback__ = ... # type: Optional[TracebackType] def __init__(self, *args: object) -> None: ... - def __getitem__(self, i: int) -> Any: ... - def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... + if sys.version_info < (3,): + def __getitem__(self, i: int) -> Any: ... + def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... + if sys.version_info >= (3,): + def with_traceback(self, tb: Optional[TracebackType]) -> BaseException: ... class GeneratorExit(BaseException): ... class KeyboardInterrupt(BaseException): ... @@ -987,63 +1414,111 @@ class SystemExit(BaseException): code = 0 class Exception(BaseException): ... class StopIteration(Exception): ... -class StandardError(Exception): ... -class ArithmeticError(StandardError): ... -class BufferError(StandardError): ... -class EnvironmentError(StandardError): - errno = 0 - strerror = ... # type: str - # TODO can this be unicode? +if sys.version_info >= (3,): + _StandardError = Exception + class OSError(Exception): + errno = 0 + strerror = ... # type: str + # filename, filename2 are actually Union[str, bytes, None] + filename = ... # type: Any + filename2 = ... # type: Any + EnvironmentError = OSError + IOError = OSError +else: + class StandardError(Exception): ... + _StandardError = StandardError + class EnvironmentError(StandardError): + errno = 0 + strerror = ... # type: str + # TODO can this be unicode? + filename = ... # type: str + class OSError(EnvironmentError): ... + class IOError(EnvironmentError): ... + +class ArithmeticError(_StandardError): ... +class AssertionError(_StandardError): ... +class AttributeError(_StandardError): ... +class BufferError(_StandardError): ... +class EOFError(_StandardError): ... +class ImportError(_StandardError): + if sys.version_info >= (3,): + name = ... # type: str + path = ... # type: str +class LookupError(_StandardError): ... +class MemoryError(_StandardError): ... +class NameError(_StandardError): ... +class ReferenceError(_StandardError): ... +class RuntimeError(_StandardError): ... +if sys.version_info >= (3, 5): + class StopAsyncIteration(Exception): + value = ... # type: Any +class SyntaxError(_StandardError): + msg = ... # type: str + lineno = ... # type: int + offset = ... # type: int + text = ... # type: str filename = ... # type: str -class LookupError(StandardError): ... -class RuntimeError(StandardError): ... -class ValueError(StandardError): ... -class AssertionError(StandardError): ... -class AttributeError(StandardError): ... -class EOFError(StandardError): ... +class SystemError(_StandardError): ... +class TypeError(_StandardError): ... +class ValueError(_StandardError): ... + class FloatingPointError(ArithmeticError): ... -class IOError(EnvironmentError): ... -class ImportError(StandardError): ... +class OverflowError(ArithmeticError): ... +class ZeroDivisionError(ArithmeticError): ... + +if sys.version_info >= (3, 6): + class ModuleNotFoundError(ImportError): ... + class IndexError(LookupError): ... class KeyError(LookupError): ... -class MemoryError(StandardError): ... -class NameError(StandardError): ... -class NotImplementedError(RuntimeError): ... -class OSError(EnvironmentError): ... + +class UnboundLocalError(NameError): ... + class WindowsError(OSError): winerror = ... # type: int -class OverflowError(ArithmeticError): ... -class ReferenceError(StandardError): ... -class SyntaxError(StandardError): - msg = ... # type: str - lineno = ... # type: int - offset = ... # type: int - text = ... # type: str - filename = ... # type: str +if sys.version_info >= (3,): + class BlockingIOError(OSError): + characters_written = 0 + class ChildProcessError(OSError): ... + class ConnectionError(OSError): ... + class BrokenPipeError(ConnectionError): ... + class ConnectionAbortedError(ConnectionError): ... + class ConnectionRefusedError(ConnectionError): ... + class ConnectionResetError(ConnectionError): ... + class FileExistsError(OSError): ... + class FileNotFoundError(OSError): ... + class InterruptedError(OSError): ... + class IsADirectoryError(OSError): ... + class NotADirectoryError(OSError): ... + class PermissionError(OSError): ... + class ProcessLookupError(OSError): ... + class TimeoutError(OSError): ... + +class NotImplementedError(RuntimeError): ... +if sys.version_info >= (3, 5): + class RecursionError(RuntimeError): ... + class IndentationError(SyntaxError): ... class TabError(IndentationError): ... -class SystemError(StandardError): ... -class TypeError(StandardError): ... -class UnboundLocalError(NameError): ... + class UnicodeError(ValueError): ... class UnicodeDecodeError(UnicodeError): - encoding: bytes + encoding: str object: bytes start: int end: int - reason: bytes - def __init__(self, __encoding: bytes, __object: bytes, __start: int, __end: int, - __reason: bytes) -> None: ... + reason: str + def __init__(self, __encoding: str, __object: bytes, __start: int, __end: int, + __reason: str) -> None: ... class UnicodeEncodeError(UnicodeError): - encoding: bytes - object: unicode + encoding: str + object: Text start: int end: int - reason: bytes - def __init__(self, __encoding: bytes, __object: unicode, __start: int, __end: int, - __reason: bytes) -> None: ... + reason: str + def __init__(self, __encoding: str, __object: Text, __start: int, __end: int, + __reason: str) -> None: ... class UnicodeTranslateError(UnicodeError): ... -class ZeroDivisionError(ArithmeticError): ... class Warning(Exception): ... class UserWarning(Warning): ... @@ -1055,45 +1530,34 @@ class PendingDeprecationWarning(Warning): ... class ImportWarning(Warning): ... class UnicodeWarning(Warning): ... class BytesWarning(Warning): ... - -def eval(s: Union[str, unicode], globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ...) -> Any: ... -def exec(object: str, - globals: Optional[Dict[str, Any]] = ..., - locals: Optional[Dict[str, Any]] = ...) -> Any: ... # TODO code object as source - -def cmp(x: Any, y: Any) -> int: ... - -def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... - -class file(BinaryIO): - @overload - def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... - @overload - def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... - @overload - def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... - def __iter__(self) -> Iterator[str]: ... - def next(self) -> str: ... - def read(self, n: int = ...) -> str: ... - def __enter__(self) -> BinaryIO: ... - def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... - def flush(self) -> None: ... - def fileno(self) -> int: ... - def isatty(self) -> bool: ... - def close(self) -> None: ... - - def readable(self) -> bool: ... - def writable(self) -> bool: ... - def seekable(self) -> bool: ... - def seek(self, offset: int, whence: int = ...) -> int: ... - def tell(self) -> int: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... - def write(self, data: str) -> int: ... - def writelines(self, data: Iterable[str]) -> None: ... - def truncate(self, pos: Optional[int] = ...) -> int: ... - -# Very old builtins -def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... -_N = TypeVar('_N', bool, int, float, complex) -def coerce(x: _N, y: _N) -> Tuple[_N, _N]: ... +if sys.version_info >= (3, 2): + class ResourceWarning(Warning): ... + +if sys.version_info < (3,): + class file(BinaryIO): + @overload + def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def next(self) -> str: ... + def read(self, n: int = ...) -> str: ... + def __enter__(self) -> BinaryIO: ... + def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... + def flush(self) -> None: ... + def fileno(self) -> int: ... + def isatty(self) -> bool: ... + def close(self) -> None: ... + + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def seekable(self) -> bool: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + def readline(self, limit: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def write(self, data: str) -> int: ... + def writelines(self, data: Iterable[str]) -> None: ... + def truncate(self, pos: Optional[int] = ...) -> int: ... diff --git a/stdlib/2/builtins.pyi b/stdlib/2/builtins.pyi index 4dc1b434bd77..cda0a31616b3 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -1,17 +1,19 @@ -# NB: __builtin__.pyi and builtins.pyi must remain consistent! -# Stubs for builtins (Python 2.7) - # True and False are deliberately omitted because they are keywords in # Python 3, and stub files conform to Python 3 syntax. from typing import ( - TypeVar, Iterator, Iterable, NoReturn, overload, - Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set, - AbstractSet, FrozenSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, - SupportsComplex, SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping, - MutableSet, ItemsView, KeysView, ValuesView, Optional, Container, Type + TypeVar, Iterator, Iterable, NoReturn, overload, Container, + Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic, + Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, + SupportsComplex, SupportsRound, IO, BinaryIO, Union, + ItemsView, KeysView, ValuesView, ByteString, Optional, AnyStr, Type, Text, ) -from abc import ABCMeta +from abc import abstractmethod, ABCMeta +from types import TracebackType, CodeType +import sys + +if sys.version_info >= (3,): + from typing import SupportsBytes _T = TypeVar('_T') _T_co = TypeVar('_T_co', covariant=True) @@ -28,8 +30,10 @@ _TT = TypeVar('_TT', bound='type') class object: __doc__ = ... # type: Optional[str] __dict__ = ... # type: Dict[str, Any] - __slots__ = ... # type: Union[str, unicode, Iterable[Union[str, unicode]]] + __slots__ = ... # type: Union[Text, Iterable[Text]] __module__ = ... # type: str + if sys.version_info >= (3, 6): + __annotations__ = ... # type: Dict[str, Any] @property def __class__(self: _T) -> Type[_T]: ... @@ -49,9 +53,15 @@ class object: def __sizeof__(self) -> int: ... def __reduce__(self) -> tuple: ... def __reduce_ex__(self, protocol: int) -> tuple: ... + if sys.version_info >= (3,): + def __dir__(self) -> Iterable[str]: ... + if sys.version_info >= (3, 6): + def __init_subclass__(cls) -> None: ... class staticmethod(object): # Special, only valid as a decorator. __func__ = ... # type: function + if sys.version_info >= (3,): + __isabstractmethod__ = ... # type: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... @@ -59,6 +69,8 @@ class staticmethod(object): # Special, only valid as a decorator. class classmethod(object): # Special, only valid as a decorator. __func__ = ... # type: function + if sys.version_info >= (3,): + __isabstractmethod__ = ... # type: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... @@ -68,40 +80,63 @@ class type(object): __bases__ = ... # type: Tuple[type, ...] __name__ = ... # type: str __module__ = ... # type: str + if sys.version_info >= (3,): + __qualname__ = ... # type: str + __dict__ = ... # type: Dict[str, Any] + __mro__ = ... # type: Tuple[type, ...] @overload def __init__(self, o: object) -> None: ... @overload def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... - # TODO: __new__ may have to be special and not a static method. @overload def __new__(cls, o: object) -> type: ... @overload def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... - - # Only new-style classes - __mro__ = ... # type: Tuple[type, ...] + def __subclasses__(self: _TT) -> List[_TT]: ... + if sys.version_info < (3,): + # Only new-style classes + __mro__ = ... # type: Tuple[type, ...] # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... - def __subclasses__(self: _TT) -> List[_TT]: ... def __instancecheck__(self, instance: Any) -> bool: ... def __subclasscheck__(self, subclass: type) -> bool: ... +class super(object): + if sys.version_info >= (3,): + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + @overload + def __init__(self) -> None: ... + else: + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + class int: @overload - def __init__(self, x: SupportsInt = ...) -> None: ... + def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ... @overload - def __init__(self, x: Union[str, unicode, bytearray], base: int = ...) -> None: ... + def __init__(self, x: Union[Text, bytes, bytearray], base: int) -> None: ... def bit_length(self) -> int: ... + if sys.version_info >= (3,): + def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ... + @classmethod + def from_bytes(cls, bytes: Sequence[int], byteorder: str, *, + signed: bool = ...) -> int: ... # TODO buffer object argument def __add__(self, x: int) -> int: ... def __sub__(self, x: int) -> int: ... def __mul__(self, x: int) -> int: ... def __floordiv__(self, x: int) -> int: ... - def __div__(self, x: int) -> int: ... + if sys.version_info < (3,): + def __div__(self, x: int) -> int: ... def __truediv__(self, x: int) -> float: ... def __mod__(self, x: int) -> int: ... def __divmod__(self, x: int) -> Tuple[int, int]: ... @@ -109,7 +144,8 @@ class int: def __rsub__(self, x: int) -> int: ... def __rmul__(self, x: int) -> int: ... def __rfloordiv__(self, x: int) -> int: ... - def __rdiv__(self, x: int) -> int: ... + if sys.version_info < (3,): + def __rdiv__(self, x: int) -> int: ... def __rtruediv__(self, x: int) -> float: ... def __rmod__(self, x: int) -> int: ... def __rdivmod__(self, x: int) -> Tuple[int, int]: ... @@ -128,6 +164,8 @@ class int: def __neg__(self) -> int: ... def __pos__(self) -> int: ... def __invert__(self) -> int: ... + if sys.version_info >= (3,): + def __round__(self, ndigits: Optional[int] = ...) -> int: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... @@ -141,11 +179,14 @@ class int: def __int__(self) -> int: ... def __abs__(self) -> int: ... def __hash__(self) -> int: ... - def __nonzero__(self) -> bool: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... def __index__(self) -> int: ... class float: - def __init__(self, x: Union[SupportsFloat, str, unicode, bytearray] = ...) -> None: ... + def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ... def as_integer_ratio(self) -> Tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @@ -156,7 +197,8 @@ class float: def __sub__(self, x: float) -> float: ... def __mul__(self, x: float) -> float: ... def __floordiv__(self, x: float) -> float: ... - def __div__(self, x: float) -> float: ... + if sys.version_info < (3,): + def __div__(self, x: float) -> float: ... def __truediv__(self, x: float) -> float: ... def __mod__(self, x: float) -> float: ... def __divmod__(self, x: float) -> Tuple[float, float]: ... @@ -165,11 +207,19 @@ class float: def __rsub__(self, x: float) -> float: ... def __rmul__(self, x: float) -> float: ... def __rfloordiv__(self, x: float) -> float: ... - def __rdiv__(self, x: float) -> float: ... + if sys.version_info < (3,): + def __rdiv__(self, x: float) -> float: ... def __rtruediv__(self, x: float) -> float: ... def __rmod__(self, x: float) -> float: ... def __rdivmod__(self, x: float) -> Tuple[float, float]: ... def __rpow__(self, x: float) -> float: ... + if sys.version_info >= (3,): + @overload + def __round__(self) -> int: ... + @overload + def __round__(self, ndigits: None) -> int: ... + @overload + def __round__(self, ndigits: int) -> float: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... @@ -185,7 +235,10 @@ class float: def __float__(self) -> float: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... - def __nonzero__(self) -> bool: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... class complex: @overload @@ -206,13 +259,15 @@ class complex: def __sub__(self, x: complex) -> complex: ... def __mul__(self, x: complex) -> complex: ... def __pow__(self, x: complex) -> complex: ... - def __div__(self, x: complex) -> complex: ... + if sys.version_info < (3,): + def __div__(self, x: complex) -> complex: ... def __truediv__(self, x: complex) -> complex: ... def __radd__(self, x: complex) -> complex: ... def __rsub__(self, x: complex) -> complex: ... def __rmul__(self, x: complex) -> complex: ... def __rpow__(self, x: complex) -> complex: ... - def __rdiv__(self, x: complex) -> complex: ... + if sys.version_info < (3,): + def __rdiv__(self, x: complex) -> complex: ... def __rtruediv__(self, x: complex) -> complex: ... def __eq__(self, x: object) -> bool: ... @@ -220,206 +275,365 @@ class complex: def __neg__(self) -> complex: ... def __pos__(self) -> complex: ... - def __complex__(self) -> complex: ... def __str__(self) -> str: ... + def __complex__(self) -> complex: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... - def __nonzero__(self) -> bool: ... - -class super(object): - @overload - def __init__(self, t: Any, obj: Any) -> None: ... - @overload - def __init__(self, t: Any) -> None: ... - -class basestring(metaclass=ABCMeta): ... - -class unicode(basestring, Sequence[unicode]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, o: object) -> None: ... - @overload - def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... - def capitalize(self) -> unicode: ... - def center(self, width: int, fillchar: unicode = ...) -> unicode: ... - def count(self, x: unicode) -> int: ... - def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... - def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... - def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., - end: int = ...) -> bool: ... - def expandtabs(self, tabsize: int = ...) -> unicode: ... - def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> unicode: ... - def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... - def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def isalnum(self) -> bool: ... - def isalpha(self) -> bool: ... - def isdecimal(self) -> bool: ... - def isdigit(self) -> bool: ... - def isidentifier(self) -> bool: ... - def islower(self) -> bool: ... - def isnumeric(self) -> bool: ... - def isprintable(self) -> bool: ... - def isspace(self) -> bool: ... - def istitle(self) -> bool: ... - def isupper(self) -> bool: ... - def join(self, iterable: Iterable[unicode]) -> unicode: ... - def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... - def lower(self) -> unicode: ... - def lstrip(self, chars: unicode = ...) -> unicode: ... - def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... - def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... - def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... - def rstrip(self, chars: unicode = ...) -> unicode: ... - def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... - def splitlines(self, keepends: bool = ...) -> List[unicode]: ... - def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., - end: int = ...) -> bool: ... - def strip(self, chars: unicode = ...) -> unicode: ... - def swapcase(self) -> unicode: ... - def title(self) -> unicode: ... - def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... - def upper(self) -> unicode: ... - def zfill(self, width: int) -> unicode: ... - - @overload - def __getitem__(self, i: int) -> unicode: ... - @overload - def __getitem__(self, s: slice) -> unicode: ... - def __getslice__(self, start: int, stop: int) -> unicode: ... - def __add__(self, s: unicode) -> unicode: ... - def __mul__(self, n: int) -> unicode: ... - def __rmul__(self, n: int) -> unicode: ... - def __mod__(self, x: Any) -> unicode: ... - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: unicode) -> bool: ... - def __le__(self, x: unicode) -> bool: ... - def __gt__(self, x: unicode) -> bool: ... - def __ge__(self, x: unicode) -> bool: ... - - def __len__(self) -> int: ... - def __contains__(self, s: object) -> bool: ... - def __iter__(self) -> Iterator[unicode]: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... + +if sys.version_info >= (3,): + _str_base = object +else: + class basestring(metaclass=ABCMeta): ... + + class unicode(basestring, Sequence[unicode]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... + def capitalize(self) -> unicode: ... + def center(self, width: int, fillchar: unicode = ...) -> unicode: ... + def count(self, x: unicode) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> unicode: ... + def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> unicode: ... + def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... + def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def isidentifier(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[unicode]) -> unicode: ... + def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def lower(self) -> unicode: ... + def lstrip(self, chars: unicode = ...) -> unicode: ... + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... + def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def rstrip(self, chars: unicode = ...) -> unicode: ... + def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[unicode]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def strip(self, chars: unicode = ...) -> unicode: ... + def swapcase(self) -> unicode: ... + def title(self) -> unicode: ... + def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... + def upper(self) -> unicode: ... + def zfill(self, width: int) -> unicode: ... + + @overload + def __getitem__(self, i: int) -> unicode: ... + @overload + def __getitem__(self, s: slice) -> unicode: ... + def __getslice__(self, start: int, stop: int) -> unicode: ... + def __add__(self, s: unicode) -> unicode: ... + def __mul__(self, n: int) -> unicode: ... + def __rmul__(self, n: int) -> unicode: ... + def __mod__(self, x: Any) -> unicode: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: unicode) -> bool: ... + def __le__(self, x: unicode) -> bool: ... + def __gt__(self, x: unicode) -> bool: ... + def __ge__(self, x: unicode) -> bool: ... + + def __len__(self) -> int: ... + def __contains__(self, s: object) -> bool: ... + def __iter__(self) -> Iterator[unicode]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + + _str_base = basestring + +class str(Sequence[str], _str_base): + if sys.version_info >= (3,): + @overload + def __init__(self, o: object = ...) -> None: ... + @overload + def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ... + else: + def __init__(self, o: object = ...) -> None: ... -class str(basestring, Sequence[str]): - def __init__(self, object: object = ...) -> None: ... def capitalize(self) -> str: ... + if sys.version_info >= (3, 3): + def casefold(self) -> str: ... def center(self, width: int, fillchar: str = ...) -> str: ... - def count(self, x: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... - def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... - def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + def count(self, x: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info < (3,): + def decode(self, encoding: Text = ..., errors: Text = ...) -> unicode: ... + def encode(self, encoding: Text = ..., errors: Text = ...) -> bytes: ... + if sys.version_info >= (3,): + def endswith(self, suffix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + else: + def endswith(self, suffix: Union[Text, Tuple[Text, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> str: ... - def find(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def format(self, *args: Any, **kwargs: Any) -> str: ... - def index(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def format_map(self, map: Mapping[str, Any]) -> str: ... + def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... + if sys.version_info >= (3,): + def isdecimal(self) -> bool: ... def isdigit(self) -> bool: ... + if sys.version_info >= (3,): + def isidentifier(self) -> bool: ... def islower(self) -> bool: ... + if sys.version_info >= (3,): + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... + if sys.version_info >= (3,): + def join(self, iterable: Iterable[str]) -> str: ... + else: + def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... def ljust(self, width: int, fillchar: str = ...) -> str: ... def lower(self) -> str: ... - @overload - def lstrip(self, chars: str = ...) -> str: ... - @overload - def lstrip(self, chars: unicode) -> unicode: ... - @overload - def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... - @overload - def partition(self, sep: str) -> Tuple[str, str, str]: ... - @overload - def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... - def rfind(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def rindex(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def lstrip(self, chars: Optional[str] = ...) -> str: ... + def partition(self, sep: str) -> Tuple[str, str, str]: ... + def replace(self, old: str, new: str, count: int = ...) -> str: ... + else: + @overload + def lstrip(self, chars: str = ...) -> str: ... + @overload + def lstrip(self, chars: unicode) -> unicode: ... + @overload + def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def partition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... + def rfind(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def rjust(self, width: int, fillchar: str = ...) -> str: ... - @overload - def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... - @overload - def rpartition(self, sep: str) -> Tuple[str, str, str]: ... - @overload - def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - @overload - def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - @overload - def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... - @overload - def rstrip(self, chars: str = ...) -> str: ... - @overload - def rstrip(self, chars: unicode) -> unicode: ... - @overload - def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - @overload - def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + if sys.version_info >= (3,): + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + def rstrip(self, chars: Optional[str] = ...) -> str: ... + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + else: + @overload + def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + @overload + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + @overload + def rstrip(self, chars: str = ...) -> str: ... + @overload + def rstrip(self, chars: unicode) -> unicode: ... + @overload + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... def splitlines(self, keepends: bool = ...) -> List[str]: ... - def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... - @overload - def strip(self, chars: str = ...) -> str: ... - @overload - def strip(self, chars: unicode) -> unicode: ... + if sys.version_info >= (3,): + def startswith(self, prefix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + def strip(self, chars: Optional[str] = ...) -> str: ... + else: + def startswith(self, prefix: Union[Text, Tuple[Text, ...]]) -> bool: ... + @overload + def strip(self, chars: str = ...) -> str: ... + @overload + def strip(self, chars: unicode) -> unicode: ... def swapcase(self) -> str: ... def title(self) -> str: ... - def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... + if sys.version_info >= (3,): + def translate(self, table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ... + else: + def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... def upper(self) -> str: ... def zfill(self, width: int) -> str: ... - - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[str]: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... - @overload - def __getitem__(self, i: int) -> str: ... - @overload - def __getitem__(self, s: slice) -> str: ... - def __getslice__(self, start: int, stop: int) -> str: ... - def __add__(self, s: AnyStr) -> AnyStr: ... - def __mul__(self, n: int) -> str: ... - def __rmul__(self, n: int) -> str: ... + if sys.version_info >= (3,): + @staticmethod + @overload + def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... + @staticmethod + @overload + def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... + + if sys.version_info >= (3,): + def __add__(self, s: str) -> str: ... + else: + def __add__(self, s: AnyStr) -> AnyStr: ... def __contains__(self, o: object) -> bool: ... def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: unicode) -> bool: ... - def __le__(self, x: unicode) -> bool: ... - def __gt__(self, x: unicode) -> bool: ... - def __ge__(self, x: unicode) -> bool: ... + def __ge__(self, x: Text) -> bool: ... + def __getitem__(self, i: Union[int, slice]) -> str: ... + def __gt__(self, x: Text) -> bool: ... + def __hash__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + def __le__(self, x: Text) -> bool: ... + def __len__(self) -> int: ... + def __lt__(self, x: Text) -> bool: ... def __mod__(self, x: Any) -> str: ... + def __mul__(self, n: int) -> str: ... + def __ne__(self, x: object) -> bool: ... + def __repr__(self) -> str: ... + def __rmul__(self, n: int) -> str: ... + def __str__(self) -> str: ... -class bytearray(MutableSequence[int]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, x: Union[Iterable[int], str]) -> None: ... - @overload - def __init__(self, x: unicode, encoding: unicode, - errors: unicode = ...) -> None: ... - @overload - def __init__(self, length: int) -> None: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> str: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + +if sys.version_info >= (3,): + class bytes(ByteString): + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str, encoding: str, + errors: str = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: SupportsBytes) -> None: ... + def capitalize(self) -> bytes: ... + def center(self, width: int, fillchar: bytes = ...) -> bytes: ... + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def decode(self, encoding: str = ..., errors: str = ...) -> str: ... + def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> bytes: ... + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytes: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def lower(self) -> bytes: ... + def lstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def replace(self, old: bytes, new: bytes, count: int = ...) -> bytes: ... + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def rstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def splitlines(self, keepends: bool = ...) -> List[bytes]: ... + def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def strip(self, chars: Optional[bytes] = ...) -> bytes: ... + def swapcase(self) -> bytes: ... + def title(self) -> bytes: ... + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ... + def upper(self) -> bytes: ... + def zfill(self, width: int) -> bytes: ... + @classmethod + def fromhex(cls, s: str) -> bytes: ... + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> bytes: ... + def __add__(self, s: bytes) -> bytes: ... + def __mul__(self, n: int) -> bytes: ... + def __rmul__(self, n: int) -> bytes: ... + if sys.version_info >= (3, 5): + def __mod__(self, value: Any) -> bytes: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: bytes) -> bool: ... + def __le__(self, x: bytes) -> bool: ... + def __gt__(self, x: bytes) -> bool: ... + def __ge__(self, x: bytes) -> bool: ... +else: + bytes = str + +class bytearray(MutableSequence[int], ByteString): + if sys.version_info >= (3,): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + else: + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str) -> None: ... + @overload + def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... def capitalize(self) -> bytearray: ... - def center(self, width: int, fillchar: str = ...) -> bytearray: ... - def count(self, x: str) -> int: ... - def decode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... - def endswith(self, suffix: Union[str, Tuple[str, ...]]) -> bool: ... + def center(self, width: int, fillchar: bytes = ...) -> bytearray: ... + if sys.version_info >= (3,): + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def copy(self) -> bytearray: ... + else: + def count(self, x: str) -> int: ... + def decode(self, encoding: Text = ..., errors: Text = ...) -> str: ... + def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytearray: ... - def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... + if sys.version_info >= (3,): + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + else: + def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... def insert(self, index: int, object: int) -> None: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -428,29 +642,43 @@ class bytearray(MutableSequence[int]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[str]) -> bytearray: ... - def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... + if sys.version_info >= (3,): + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytearray: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + else: + def join(self, iterable: Iterable[str]) -> bytearray: ... + def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... def lower(self) -> bytearray: ... - def lstrip(self, chars: str = ...) -> bytearray: ... - def partition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... - def replace(self, old: str, new: str, count: int = ...) -> bytearray: ... - def rfind(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def rindex(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def rjust(self, width: int, fillchar: str = ...) -> bytearray: ... - def rpartition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... - def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... - def rstrip(self, chars: str = ...) -> bytearray: ... - def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def lstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... + def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... + def replace(self, old: bytes, new: bytes, count: int = ...) -> bytearray: ... + if sys.version_info >= (3,): + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + else: + def rfind(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def rstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... - def startswith(self, prefix: Union[str, Tuple[str, ...]]) -> bool: ... - def strip(self, chars: str = ...) -> bytearray: ... + def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def strip(self, chars: Optional[bytes] = ...) -> bytearray: ... def swapcase(self) -> bytearray: ... def title(self) -> bytearray: ... - def translate(self, table: str) -> bytearray: ... + if sys.version_info >= (3,): + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ... + else: + def translate(self, table: str) -> bytearray: ... def upper(self) -> bytearray: ... def zfill(self, width: int) -> bytearray: ... @staticmethod - def fromhex(x: str) -> bytearray: ... + def fromhex(s: str) -> bytearray: ... + if sys.version_info >= (3,): + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ... @@ -463,23 +691,74 @@ class bytearray(MutableSequence[int]): def __getitem__(self, i: int) -> int: ... @overload def __getitem__(self, s: slice) -> bytearray: ... - def __getslice__(self, start: int, stop: int) -> bytearray: ... @overload def __setitem__(self, i: int, x: int) -> None: ... @overload - def __setitem__(self, s: slice, x: Union[Iterable[int], str]) -> None: ... - def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... + def __setitem__(self, s: slice, x: Union[Iterable[int], bytes]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... - def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, s: str) -> bytearray: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> bytearray: ... + def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + def __add__(self, s: bytes) -> bytearray: ... + if sys.version_info >= (3,): + def __iadd__(self, s: Iterable[int]) -> bytearray: ... def __mul__(self, n: int) -> bytearray: ... + if sys.version_info >= (3,): + def __rmul__(self, n: int) -> bytearray: ... + def __imul__(self, n: int) -> bytearray: ... + if sys.version_info >= (3, 5): + def __mod__(self, value: Any) -> bytes: ... def __contains__(self, o: object) -> bool: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: str) -> bool: ... - def __le__(self, x: str) -> bool: ... - def __gt__(self, x: str) -> bool: ... - def __ge__(self, x: str) -> bool: ... + def __lt__(self, x: bytes) -> bool: ... + def __le__(self, x: bytes) -> bool: ... + def __gt__(self, x: bytes) -> bool: ... + def __ge__(self, x: bytes) -> bool: ... + +if sys.version_info >= (3,): + _mv_container_type = int +else: + _mv_container_type = str + +class memoryview(Sized, Container[_mv_container_type]): + format = ... # type: str + itemsize = ... # type: int + shape = ... # type: Optional[Tuple[int, ...]] + strides = ... # type: Optional[Tuple[int, ...]] + suboffsets = ... # type: Optional[Tuple[int, ...]] + readonly = ... # type: bool + ndim = ... # type: int + + if sys.version_info >= (3,): + def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... + def __enter__(self) -> memoryview: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ... + else: + def __init__(self, obj: Union[bytes, bytearray, buffer, memoryview]) -> None: ... + + @overload + def __getitem__(self, i: int) -> _mv_container_type: ... + @overload + def __getitem__(self, s: slice) -> memoryview: ... + + def __contains__(self, x: object) -> bool: ... + def __iter__(self) -> Iterator[_mv_container_type]: ... + def __len__(self) -> int: ... + + @overload + def __setitem__(self, i: int, o: bytes) -> None: ... + @overload + def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... + @overload + def __setitem__(self, s: slice, o: memoryview) -> None: ... + + def tobytes(self) -> bytes: ... + def tolist(self) -> List[int]: ... + + if sys.version_info >= (3, 5): + def hex(self) -> str: ... class bool(int): def __init__(self, o: object = ...) -> None: ... @@ -535,18 +814,28 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... - def index(self, x: Any) -> int: ... + if sys.version_info >= (3, 5): + def index(self, x: Any, start: int = ..., end: int = ...) -> int: ... + else: + def index(self, x: Any) -> int: ... class function: - # TODO name of the class (corresponds to Python 'function' class) + # TODO not defined in builtins! __name__ = ... # type: str __module__ = ... # type: str + if sys.version_info >= (3,): + __qualname__ = ... # type: str + __code__ = ... # type: CodeType + __annotations__ = ... # type: Dict[str, Any] class list(MutableSequence[_T], Generic[_T]): @overload def __init__(self) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... + if sys.version_info >= (3,): + def clear(self) -> None: ... + def copy(self) -> List[_T]: ... def append(self, object: _T) -> None: ... def extend(self, iterable: Iterable[_T]) -> None: ... def pop(self, index: int = ...) -> _T: ... @@ -555,7 +844,10 @@ class list(MutableSequence[_T], Generic[_T]): def insert(self, index: int, object: _T) -> None: ... def remove(self, object: _T) -> None: ... def reverse(self) -> None: ... - def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... + if sys.version_info >= (3,): + def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ... + else: + def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... @@ -565,18 +857,21 @@ class list(MutableSequence[_T], Generic[_T]): def __getitem__(self, i: int) -> _T: ... @overload def __getitem__(self, s: slice) -> List[_T]: ... - def __getslice__(self, start: int, stop: int) -> List[_T]: ... @overload def __setitem__(self, i: int, o: _T) -> None: ... @overload def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... - def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... - def __delslice__(self, start: int, stop: int) -> None: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> List[_T]: ... + def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self, x: List[_T]) -> List[_T]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... + if sys.version_info >= (3,): + def __imul__(self, n: int) -> List[_T]: ... def __contains__(self, o: object) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... def __gt__(self, x: List[_T]) -> bool: ... @@ -596,29 +891,35 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... - def has_key(self, k: _KT) -> bool: ... + if sys.version_info < (3,): + def has_key(self, k: _KT) -> bool: ... def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... def popitem(self) -> Tuple[_KT, _VT]: ... - def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... + def setdefault(self, k: _KT, default: Optional[_VT] = ...) -> _VT: ... @overload def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... @overload def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... @overload def update(self, **kwargs: _VT) -> None: ... - def iterkeys(self) -> Iterator[_KT]: ... - def itervalues(self) -> Iterator[_VT]: ... - def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... - def viewkeys(self) -> KeysView[_KT]: ... - def viewvalues(self) -> ValuesView[_VT]: ... - def viewitems(self) -> ItemsView[_KT, _VT]: ... + if sys.version_info >= (3,): + def keys(self) -> KeysView[_KT]: ... + def values(self) -> ValuesView[_VT]: ... + def items(self) -> ItemsView[_KT, _VT]: ... + else: + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def viewkeys(self) -> KeysView[_KT]: ... + def viewvalues(self) -> ValuesView[_VT]: ... + def viewitems(self) -> ItemsView[_KT, _VT]: ... @staticmethod @overload - def fromkeys(seq: Sequence[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) + def fromkeys(seq: Iterable[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) @staticmethod @overload - def fromkeys(seq: Sequence[_T], value: _S) -> Dict[_T, _S]: ... + def fromkeys(seq: Iterable[_T], value: _S) -> Dict[_T, _S]: ... def __len__(self) -> int: ... def __getitem__(self, k: _KT) -> _VT: ... def __setitem__(self, k: _KT, v: _VT) -> None: ... @@ -636,9 +937,9 @@ class set(MutableSet[_T], Generic[_T]): def discard(self, element: _T) -> None: ... def intersection(self, *s: Iterable[Any]) -> Set[_T]: ... def intersection_update(self, *s: Iterable[Any]) -> None: ... - def isdisjoint(self, s: Iterable[object]) -> bool: ... - def issubset(self, s: Iterable[object]) -> bool: ... - def issuperset(self, s: Iterable[object]) -> bool: ... + def isdisjoint(self, s: Iterable[Any]) -> bool: ... + def issubset(self, s: Iterable[Any]) -> bool: ... + def issuperset(self, s: Iterable[Any]) -> bool: ... def pop(self) -> _T: ... def remove(self, element: _T) -> None: ... def symmetric_difference(self, s: Iterable[_T]) -> Set[_T]: ... @@ -663,10 +964,7 @@ class set(MutableSet[_T], Generic[_T]): def __gt__(self, s: AbstractSet[object]) -> bool: ... class frozenset(AbstractSet[_T], Generic[_T]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, iterable: Iterable[_T]) -> None: ... + def __init__(self, iterable: Iterable[_T] = ...) -> None: ... def copy(self) -> FrozenSet[_T]: ... def difference(self, *s: Iterable[object]) -> FrozenSet[_T]: ... def intersection(self, *s: Iterable[object]) -> FrozenSet[_T]: ... @@ -691,23 +989,48 @@ class frozenset(AbstractSet[_T], Generic[_T]): class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... def __iter__(self) -> Iterator[Tuple[int, _T]]: ... - def next(self) -> Tuple[int, _T]: ... + if sys.version_info >= (3,): + def __next__(self) -> Tuple[int, _T]: ... + else: + def next(self) -> Tuple[int, _T]: ... # TODO __getattribute__ -class xrange(Sized, Iterable[int], Reversible[int]): - @overload - def __init__(self, stop: int) -> None: ... - @overload - def __init__(self, start: int, stop: int, step: int = ...) -> None: ... - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[int]: ... - def __getitem__(self, i: int) -> int: ... - def __reversed__(self) -> Iterator[int]: ... +if sys.version_info >= (3,): + class range(Sequence[int]): + start = ... # type: int + stop = ... # type: int + step = ... # type: int + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def count(self, value: int) -> int: ... + def index(self, value: int, start: int = ..., stop: Optional[int] = ...) -> int: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[int]: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> range: ... + def __repr__(self) -> str: ... + def __reversed__(self) -> Iterator[int]: ... +else: + class xrange(Sized, Iterable[int], Reversible[int]): + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __getitem__(self, i: int) -> int: ... + def __reversed__(self) -> Iterator[int]: ... class property(object): def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., fset: Optional[Callable[[Any, Any], None]] = ..., - fdel: Optional[Callable[[Any], None]] = ..., doc: Optional[str] = ...) -> None: ... + fdel: Optional[Callable[[Any], None]] = ..., + doc: Optional[str] = ...) -> None: ... def getter(self, fget: Callable[[Any], Any]) -> property: ... def setter(self, fset: Callable[[Any, Any], None]) -> property: ... def deleter(self, fdel: Callable[[Any], None]) -> property: ... @@ -718,49 +1041,84 @@ class property(object): def fset(self, value: Any) -> None: ... def fdel(self) -> None: ... -long = int -bytes = str +if sys.version_info < (3,): + long = int NotImplemented = ... # type: Any def abs(n: SupportsAbs[_T]) -> _T: ... def all(i: Iterable[object]) -> bool: ... def any(i: Iterable[object]) -> bool: ... +if sys.version_info < (3,): + def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... +if sys.version_info >= (3,): + def ascii(o: object) -> str: ... def bin(number: int) -> str: ... +if sys.version_info >= (3, 7): + def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(o: object) -> bool: ... def chr(code: int) -> str: ... -def compile(source: Any, filename: unicode, mode: str, flags: int = ..., - dont_inherit: int = ...) -> Any: ... -def delattr(o: Any, name: unicode) -> None: ... +if sys.version_info < (3,): + def cmp(x: Any, y: Any) -> int: ... + _N1 = TypeVar('_N1', bool, int, float, complex) + def coerce(x: _N1, y: _N1) -> Tuple[_N1, _N1]: ... +if sys.version_info >= (3, 6): + # This class is to be exported as PathLike from os, + # but we define it here as _PathLike to avoid import cycle issues. + # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 + class _PathLike(Generic[AnyStr]): + def __fspath__(self) -> AnyStr: ... + def compile(source: Any, filename: Union[str, bytes, _PathLike], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... +else: + def compile(source: Any, filename: Union[str, bytes], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... +if sys.version_info >= (3,): + def copyright() -> None: ... + def credits() -> None: ... +def delattr(o: Any, name: Text) -> None: ... def dir(o: object = ...) -> List[str]: ... -@overload -def divmod(a: int, b: int) -> Tuple[int, int]: ... -@overload -def divmod(a: float, b: float) -> Tuple[float, float]: ... +_N2 = TypeVar('_N2', int, float) +def divmod(a: _N2, b: _N2) -> Tuple[_N2, _N2]: ... +def eval(source: Union[Text, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +if sys.version_info >= (3,): + def exec(object: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +else: + def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... def exit(code: Any = ...) -> NoReturn: ... -@overload -def filter(__function: Callable[[AnyStr], Any], # type: ignore - __iterable: AnyStr) -> AnyStr: ... -@overload -def filter(__function: None, # type: ignore - __iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ... -@overload -def filter(__function: Callable[[_T], Any], # type: ignore - __iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ... -@overload -def filter(__function: None, - __iterable: Iterable[Optional[_T]]) -> List[_T]: ... -@overload -def filter(__function: Callable[[_T], Any], - __iterable: Iterable[_T]) -> List[_T]: ... +if sys.version_info >= (3,): + @overload + def filter(__function: None, __iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... + @overload + def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Iterator[_T]: ... +else: + @overload + def filter(__function: Callable[[AnyStr], Any], # type: ignore + __iterable: AnyStr) -> AnyStr: ... + @overload + def filter(__function: None, # type: ignore + __iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ... + @overload + def filter(__function: Callable[[_T], Any], # type: ignore + __iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ... + @overload + def filter(__function: None, + __iterable: Iterable[Optional[_T]]) -> List[_T]: ... + @overload + def filter(__function: Callable[[_T], Any], + __iterable: Iterable[_T]) -> List[_T]: ... def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode -def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ... -def hasattr(o: Any, name: unicode) -> bool: ... +def getattr(o: Any, name: Text, default: Any = ...) -> Any: ... +def globals() -> Dict[str, Any]: ... +def hasattr(o: Any, name: Text) -> bool: ... def hash(o: object) -> int: ... +if sys.version_info >= (3,): + def help(*args: Any, **kwds: Any) -> None: ... def hex(i: int) -> str: ... # TODO __index__ def id(o: object) -> int: ... -def input(prompt: Any = ...) -> Any: ... -def intern(string: str) -> str: ... +if sys.version_info >= (3,): + def input(prompt: Any = ...) -> str: ... +else: + def input(prompt: Any = ...) -> Any: ... + def intern(string: str) -> str: ... @overload def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... @overload @@ -768,218 +1126,287 @@ def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ... def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... def issubclass(cls: type, classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... def len(o: Sized) -> int: ... -@overload -def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... -@overload -def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... -@overload -def map(func: None, - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -@overload -def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3, _T4], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> List[_S]: ... -@overload -def map(func: Callable[..., _S], - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[_S]: ... -@overload -def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +if sys.version_info >= (3,): + def license() -> None: ... +def locals() -> Dict[str, Any]: ... +if sys.version_info >= (3,): + @overload + def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> Iterator[_S]: ... + @overload + def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[_S]: ... +else: + @overload + def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... + @overload + def map(func: None, + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... + @overload + def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[_S]: ... + @overload + def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[_S]: ... +if sys.version_info >= (3,): + @overload + def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +else: + @overload + def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +if sys.version_info >= (3,): + @overload + def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +else: + @overload + def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... @overload def next(i: Iterator[_T]) -> _T: ... @overload def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... def oct(i: int) -> str: ... # TODO __index__ + +if sys.version_info >= (3, 6): + def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... +elif sys.version_info >= (3,): + def open(file: Union[str, bytes, int], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... +else: + def open(file: Union[unicode, int], mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... + +def ord(c: Union[str, bytes]) -> int: ... +if sys.version_info >= (3,): + def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[str]] = ..., flush: bool = ...) -> None: ... +else: + # This is only available after from __future__ import print_function. + def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[Any]] = ...) -> None: ... @overload -def open(file: str, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... -@overload -def open(file: unicode, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... -@overload -def open(file: int, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... -def ord(c: unicode) -> int: ... -# This is only available after from __future__ import print_function. -def print(*values: Any, sep: unicode = ..., end: unicode = ..., - file: IO[Any] = ...) -> None: ... -@overload -def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y. +def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y @overload def pow(x: int, y: int, z: int) -> Any: ... @overload def pow(x: float, y: float) -> float: ... @overload def pow(x: float, y: float, z: float) -> float: ... -def quit(code: int = ...) -> None: ... -def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... -def raw_input(prompt: Any = ...) -> str: ... - -@overload -def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... -@overload -def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... - -def reload(module: Any) -> Any: ... +def quit(code: Optional[int] = ...) -> None: ... +if sys.version_info < (3,): + def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... + def raw_input(prompt: Any = ...) -> str: ... + @overload + def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... + @overload + def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... + def reload(module: Any) -> Any: ... @overload def reversed(object: Sequence[_T]) -> Iterator[_T]: ... @overload def reversed(object: Reversible[_T]) -> Iterator[_T]: ... def repr(o: object) -> str: ... -@overload -def round(number: float) -> float: ... -@overload -def round(number: float, ndigits: int) -> float: ... # Always return a float if given ndigits. -@overload -def round(number: SupportsRound[_T]) -> _T: ... -@overload -def round(number: SupportsRound[_T], ndigits: int) -> _T: ... -def setattr(object: Any, name: unicode, value: Any) -> None: ... -def sorted(iterable: Iterable[_T], *, - cmp: Callable[[_T, _T], int] = ..., - key: Callable[[_T], Any] = ..., - reverse: bool = ...) -> List[_T]: ... +if sys.version_info >= (3,): + @overload + def round(number: float) -> int: ... + @overload + def round(number: float, ndigits: None) -> int: ... + @overload + def round(number: float, ndigits: int) -> float: ... + @overload + def round(number: SupportsRound[_T]) -> int: ... + @overload + def round(number: SupportsRound[_T], ndigits: None) -> int: ... # type: ignore + @overload + def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +else: + @overload + def round(number: float) -> float: ... + @overload + def round(number: float, ndigits: int) -> float: ... + @overload + def round(number: SupportsRound[_T]) -> _T: ... + @overload + def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +def setattr(object: Any, name: Text, value: Any) -> None: ... +if sys.version_info >= (3,): + def sorted(iterable: Iterable[_T], *, + key: Optional[Callable[[_T], Any]] = ..., + reverse: bool = ...) -> List[_T]: ... +else: + def sorted(iterable: Iterable[_T], *, + cmp: Callable[[_T, _T], int] = ..., + key: Callable[[_T], Any] = ..., + reverse: bool = ...) -> List[_T]: ... @overload def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... @overload def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... -def unichr(i: int) -> unicode: ... +if sys.version_info < (3,): + def unichr(i: int) -> unicode: ... def vars(object: Any = ...) -> Dict[str, Any]: ... -@overload -def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... -@overload -def zip(iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, - _T3, _T4]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, - _T3, _T4, _T5]]: ... -@overload -def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], - iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -def __import__(name: unicode, - globals: Dict[str, Any] = ..., - locals: Dict[str, Any] = ..., +if sys.version_info >= (3,): + @overload + def zip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... + @overload + def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... +else: + @overload + def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... + @overload + def zip(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, + _T3, _T4]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... + @overload + def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... +def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., fromlist: List[str] = ..., level: int = ...) -> Any: ... -def globals() -> Dict[str, Any]: ... -def locals() -> Dict[str, Any]: ... - # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. class ellipsis: ... Ellipsis = ... # type: ellipsis -# TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. -_AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) - -class buffer(Sized): - def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... - def __add__(self, other: _AnyBuffer) -> str: ... - def __cmp__(self, other: _AnyBuffer) -> bool: ... - def __getitem__(self, key: Union[int, slice]) -> str: ... - def __getslice__(self, i: int, j: int) -> str: ... - def __len__(self) -> int: ... - def __mul__(self, x: int) -> str: ... - -class memoryview(Sized, Container[bytes]): - format = ... # type: str - itemsize = ... # type: int - shape = ... # type: Optional[Tuple[int, ...]] - strides = ... # type: Optional[Tuple[int, ...]] - suboffsets = ... # type: Optional[Tuple[int, ...]] - readonly = ... # type: bool - ndim = ... # type: int - - def __init__(self, obj: Union[str, bytearray, buffer, memoryview]) -> None: ... - - @overload - def __getitem__(self, i: int) -> bytes: ... - @overload - def __getitem__(self, s: slice) -> memoryview: ... - - def __contains__(self, x: object) -> bool: ... - def __iter__(self) -> Iterator[bytes]: ... - def __len__(self) -> int: ... - - @overload - def __setitem__(self, i: int, o: bytes) -> None: ... - @overload - def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... - @overload - def __setitem__(self, s: slice, o: memoryview) -> None: ... +if sys.version_info < (3,): + # TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. + _AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) - def tobytes(self) -> bytes: ... - def tolist(self) -> List[int]: ... + class buffer(Sized): + def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... + def __add__(self, other: _AnyBuffer) -> str: ... + def __cmp__(self, other: _AnyBuffer) -> bool: ... + def __getitem__(self, key: Union[int, slice]) -> str: ... + def __getslice__(self, i: int, j: int) -> str: ... + def __len__(self) -> int: ... + def __mul__(self, x: int) -> str: ... class BaseException(object): args = ... # type: Tuple[Any, ...] - message = ... # type: Any + if sys.version_info < (3,): + message = ... # type: Any + if sys.version_info >= (3,): + __cause__ = ... # type: Optional[BaseException] + __context__ = ... # type: Optional[BaseException] + __traceback__ = ... # type: Optional[TracebackType] def __init__(self, *args: object) -> None: ... - def __getitem__(self, i: int) -> Any: ... - def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... + if sys.version_info < (3,): + def __getitem__(self, i: int) -> Any: ... + def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... + if sys.version_info >= (3,): + def with_traceback(self, tb: Optional[TracebackType]) -> BaseException: ... class GeneratorExit(BaseException): ... class KeyboardInterrupt(BaseException): ... @@ -987,63 +1414,111 @@ class SystemExit(BaseException): code = 0 class Exception(BaseException): ... class StopIteration(Exception): ... -class StandardError(Exception): ... -class ArithmeticError(StandardError): ... -class BufferError(StandardError): ... -class EnvironmentError(StandardError): - errno = 0 - strerror = ... # type: str - # TODO can this be unicode? +if sys.version_info >= (3,): + _StandardError = Exception + class OSError(Exception): + errno = 0 + strerror = ... # type: str + # filename, filename2 are actually Union[str, bytes, None] + filename = ... # type: Any + filename2 = ... # type: Any + EnvironmentError = OSError + IOError = OSError +else: + class StandardError(Exception): ... + _StandardError = StandardError + class EnvironmentError(StandardError): + errno = 0 + strerror = ... # type: str + # TODO can this be unicode? + filename = ... # type: str + class OSError(EnvironmentError): ... + class IOError(EnvironmentError): ... + +class ArithmeticError(_StandardError): ... +class AssertionError(_StandardError): ... +class AttributeError(_StandardError): ... +class BufferError(_StandardError): ... +class EOFError(_StandardError): ... +class ImportError(_StandardError): + if sys.version_info >= (3,): + name = ... # type: str + path = ... # type: str +class LookupError(_StandardError): ... +class MemoryError(_StandardError): ... +class NameError(_StandardError): ... +class ReferenceError(_StandardError): ... +class RuntimeError(_StandardError): ... +if sys.version_info >= (3, 5): + class StopAsyncIteration(Exception): + value = ... # type: Any +class SyntaxError(_StandardError): + msg = ... # type: str + lineno = ... # type: int + offset = ... # type: int + text = ... # type: str filename = ... # type: str -class LookupError(StandardError): ... -class RuntimeError(StandardError): ... -class ValueError(StandardError): ... -class AssertionError(StandardError): ... -class AttributeError(StandardError): ... -class EOFError(StandardError): ... +class SystemError(_StandardError): ... +class TypeError(_StandardError): ... +class ValueError(_StandardError): ... + class FloatingPointError(ArithmeticError): ... -class IOError(EnvironmentError): ... -class ImportError(StandardError): ... +class OverflowError(ArithmeticError): ... +class ZeroDivisionError(ArithmeticError): ... + +if sys.version_info >= (3, 6): + class ModuleNotFoundError(ImportError): ... + class IndexError(LookupError): ... class KeyError(LookupError): ... -class MemoryError(StandardError): ... -class NameError(StandardError): ... -class NotImplementedError(RuntimeError): ... -class OSError(EnvironmentError): ... + +class UnboundLocalError(NameError): ... + class WindowsError(OSError): winerror = ... # type: int -class OverflowError(ArithmeticError): ... -class ReferenceError(StandardError): ... -class SyntaxError(StandardError): - msg = ... # type: str - lineno = ... # type: int - offset = ... # type: int - text = ... # type: str - filename = ... # type: str +if sys.version_info >= (3,): + class BlockingIOError(OSError): + characters_written = 0 + class ChildProcessError(OSError): ... + class ConnectionError(OSError): ... + class BrokenPipeError(ConnectionError): ... + class ConnectionAbortedError(ConnectionError): ... + class ConnectionRefusedError(ConnectionError): ... + class ConnectionResetError(ConnectionError): ... + class FileExistsError(OSError): ... + class FileNotFoundError(OSError): ... + class InterruptedError(OSError): ... + class IsADirectoryError(OSError): ... + class NotADirectoryError(OSError): ... + class PermissionError(OSError): ... + class ProcessLookupError(OSError): ... + class TimeoutError(OSError): ... + +class NotImplementedError(RuntimeError): ... +if sys.version_info >= (3, 5): + class RecursionError(RuntimeError): ... + class IndentationError(SyntaxError): ... class TabError(IndentationError): ... -class SystemError(StandardError): ... -class TypeError(StandardError): ... -class UnboundLocalError(NameError): ... + class UnicodeError(ValueError): ... class UnicodeDecodeError(UnicodeError): - encoding: bytes + encoding: str object: bytes start: int end: int - reason: bytes - def __init__(self, __encoding: bytes, __object: bytes, __start: int, __end: int, - __reason: bytes) -> None: ... + reason: str + def __init__(self, __encoding: str, __object: bytes, __start: int, __end: int, + __reason: str) -> None: ... class UnicodeEncodeError(UnicodeError): - encoding: bytes - object: unicode + encoding: str + object: Text start: int end: int - reason: bytes - def __init__(self, __encoding: bytes, __object: unicode, __start: int, __end: int, - __reason: bytes) -> None: ... + reason: str + def __init__(self, __encoding: str, __object: Text, __start: int, __end: int, + __reason: str) -> None: ... class UnicodeTranslateError(UnicodeError): ... -class ZeroDivisionError(ArithmeticError): ... class Warning(Exception): ... class UserWarning(Warning): ... @@ -1055,45 +1530,34 @@ class PendingDeprecationWarning(Warning): ... class ImportWarning(Warning): ... class UnicodeWarning(Warning): ... class BytesWarning(Warning): ... - -def eval(s: Union[str, unicode], globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ...) -> Any: ... -def exec(object: str, - globals: Optional[Dict[str, Any]] = ..., - locals: Optional[Dict[str, Any]] = ...) -> Any: ... # TODO code object as source - -def cmp(x: Any, y: Any) -> int: ... - -def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... - -class file(BinaryIO): - @overload - def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... - @overload - def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... - @overload - def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... - def __iter__(self) -> Iterator[str]: ... - def next(self) -> str: ... - def read(self, n: int = ...) -> str: ... - def __enter__(self) -> BinaryIO: ... - def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... - def flush(self) -> None: ... - def fileno(self) -> int: ... - def isatty(self) -> bool: ... - def close(self) -> None: ... - - def readable(self) -> bool: ... - def writable(self) -> bool: ... - def seekable(self) -> bool: ... - def seek(self, offset: int, whence: int = ...) -> int: ... - def tell(self) -> int: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... - def write(self, data: str) -> int: ... - def writelines(self, data: Iterable[str]) -> None: ... - def truncate(self, pos: Optional[int] = ...) -> int: ... - -# Very old builtins -def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... -_N = TypeVar('_N', bool, int, float, complex) -def coerce(x: _N, y: _N) -> Tuple[_N, _N]: ... +if sys.version_info >= (3, 2): + class ResourceWarning(Warning): ... + +if sys.version_info < (3,): + class file(BinaryIO): + @overload + def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def next(self) -> str: ... + def read(self, n: int = ...) -> str: ... + def __enter__(self) -> BinaryIO: ... + def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... + def flush(self) -> None: ... + def fileno(self) -> int: ... + def isatty(self) -> bool: ... + def close(self) -> None: ... + + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def seekable(self) -> bool: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + def readline(self, limit: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def write(self, data: str) -> int: ... + def writelines(self, data: Iterable[str]) -> None: ... + def truncate(self, pos: Optional[int] = ...) -> int: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index b75254d06dde..cda0a31616b3 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -1,18 +1,19 @@ -# Stubs for builtins (Python 3) +# True and False are deliberately omitted because they are keywords in +# Python 3, and stub files conform to Python 3 syntax. from typing import ( - TypeVar, Iterator, Iterable, overload, Container, - Sequence, MutableSequence, Mapping, MutableMapping, NoReturn, Tuple, List, Any, Dict, Callable, Generic, - Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, - SupportsComplex, SupportsBytes, SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, - ValuesView, ByteString, Optional, AnyStr, Type, + TypeVar, Iterator, Iterable, NoReturn, overload, Container, + Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic, + Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, + SupportsComplex, SupportsRound, IO, BinaryIO, Union, + ItemsView, KeysView, ValuesView, ByteString, Optional, AnyStr, Type, Text, ) from abc import abstractmethod, ABCMeta from types import TracebackType, CodeType import sys -# Note that names imported above are not automatically made visible via the -# implicit builtins import. +if sys.version_info >= (3,): + from typing import SupportsBytes _T = TypeVar('_T') _T_co = TypeVar('_T_co', covariant=True) @@ -29,7 +30,7 @@ _TT = TypeVar('_TT', bound='type') class object: __doc__ = ... # type: Optional[str] __dict__ = ... # type: Dict[str, Any] - __slots__ = ... # type: Union[str, Iterable[str]] + __slots__ = ... # type: Union[Text, Iterable[Text]] __module__ = ... # type: str if sys.version_info >= (3, 6): __annotations__ = ... # type: Dict[str, Any] @@ -52,34 +53,37 @@ class object: def __sizeof__(self) -> int: ... def __reduce__(self) -> tuple: ... def __reduce_ex__(self, protocol: int) -> tuple: ... - def __dir__(self) -> Iterable[str]: ... - + if sys.version_info >= (3,): + def __dir__(self) -> Iterable[str]: ... if sys.version_info >= (3, 6): def __init_subclass__(cls) -> None: ... -class staticmethod: # Special, only valid as a decorator. +class staticmethod(object): # Special, only valid as a decorator. __func__ = ... # type: function - __isabstractmethod__ = ... # type: bool + if sys.version_info >= (3,): + __isabstractmethod__ = ... # type: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... -class classmethod: # Special, only valid as a decorator. +class classmethod(object): # Special, only valid as a decorator. __func__ = ... # type: function - __isabstractmethod__ = ... # type: bool + if sys.version_info >= (3,): + __isabstractmethod__ = ... # type: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... -class type: +class type(object): __bases__ = ... # type: Tuple[type, ...] __name__ = ... # type: str - __qualname__ = ... # type: str __module__ = ... # type: str - __dict__ = ... # type: Dict[str, Any] - __mro__ = ... # type: Tuple[type, ...] + if sys.version_info >= (3,): + __qualname__ = ... # type: str + __dict__ = ... # type: Dict[str, Any] + __mro__ = ... # type: Tuple[type, ...] @overload def __init__(self, o: object) -> None: ... @@ -91,36 +95,48 @@ class type: def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... def __subclasses__(self: _TT) -> List[_TT]: ... + if sys.version_info < (3,): + # Only new-style classes + __mro__ = ... # type: Tuple[type, ...] # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... def __instancecheck__(self, instance: Any) -> bool: ... def __subclasscheck__(self, subclass: type) -> bool: ... -class super: - @overload - def __init__(self, t: Any, obj: Any) -> None: ... - @overload - def __init__(self, t: Any) -> None: ... - @overload - def __init__(self) -> None: ... +class super(object): + if sys.version_info >= (3,): + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + @overload + def __init__(self) -> None: ... + else: + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... class int: @overload - def __init__(self, x: Union[str, bytes, SupportsInt] = ...) -> None: ... + def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ... @overload - def __init__(self, x: Union[str, bytes], base: int) -> None: ... + def __init__(self, x: Union[Text, bytes, bytearray], base: int) -> None: ... def bit_length(self) -> int: ... - def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ... - @classmethod - def from_bytes(cls, bytes: Sequence[int], byteorder: str, *, - signed: bool = ...) -> int: ... # TODO buffer object argument + if sys.version_info >= (3,): + def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ... + @classmethod + def from_bytes(cls, bytes: Sequence[int], byteorder: str, *, + signed: bool = ...) -> int: ... # TODO buffer object argument def __add__(self, x: int) -> int: ... def __sub__(self, x: int) -> int: ... def __mul__(self, x: int) -> int: ... def __floordiv__(self, x: int) -> int: ... + if sys.version_info < (3,): + def __div__(self, x: int) -> int: ... def __truediv__(self, x: int) -> float: ... def __mod__(self, x: int) -> int: ... def __divmod__(self, x: int) -> Tuple[int, int]: ... @@ -128,6 +144,8 @@ class int: def __rsub__(self, x: int) -> int: ... def __rmul__(self, x: int) -> int: ... def __rfloordiv__(self, x: int) -> int: ... + if sys.version_info < (3,): + def __rdiv__(self, x: int) -> int: ... def __rtruediv__(self, x: int) -> float: ... def __rmod__(self, x: int) -> int: ... def __rdivmod__(self, x: int) -> Tuple[int, int]: ... @@ -146,7 +164,8 @@ class int: def __neg__(self) -> int: ... def __pos__(self) -> int: ... def __invert__(self) -> int: ... - def __round__(self, ndigits: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def __round__(self, ndigits: Optional[int] = ...) -> int: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... @@ -160,11 +179,14 @@ class int: def __int__(self) -> int: ... def __abs__(self) -> int: ... def __hash__(self) -> int: ... - def __bool__(self) -> bool: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... def __index__(self) -> int: ... class float: - def __init__(self, x: Union[SupportsFloat, str, bytes] = ...) -> None: ... + def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ... def as_integer_ratio(self) -> Tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @@ -175,6 +197,8 @@ class float: def __sub__(self, x: float) -> float: ... def __mul__(self, x: float) -> float: ... def __floordiv__(self, x: float) -> float: ... + if sys.version_info < (3,): + def __div__(self, x: float) -> float: ... def __truediv__(self, x: float) -> float: ... def __mod__(self, x: float) -> float: ... def __divmod__(self, x: float) -> Tuple[float, float]: ... @@ -183,16 +207,19 @@ class float: def __rsub__(self, x: float) -> float: ... def __rmul__(self, x: float) -> float: ... def __rfloordiv__(self, x: float) -> float: ... + if sys.version_info < (3,): + def __rdiv__(self, x: float) -> float: ... def __rtruediv__(self, x: float) -> float: ... def __rmod__(self, x: float) -> float: ... def __rdivmod__(self, x: float) -> Tuple[float, float]: ... def __rpow__(self, x: float) -> float: ... - @overload - def __round__(self) -> int: ... - @overload - def __round__(self, ndigits: None) -> int: ... - @overload - def __round__(self, ndigits: int) -> float: ... + if sys.version_info >= (3,): + @overload + def __round__(self) -> int: ... + @overload + def __round__(self, ndigits: None) -> int: ... + @overload + def __round__(self, ndigits: int) -> float: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... @@ -208,7 +235,10 @@ class float: def __float__(self) -> float: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... - def __bool__(self) -> bool: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... class complex: @overload @@ -229,11 +259,15 @@ class complex: def __sub__(self, x: complex) -> complex: ... def __mul__(self, x: complex) -> complex: ... def __pow__(self, x: complex) -> complex: ... + if sys.version_info < (3,): + def __div__(self, x: complex) -> complex: ... def __truediv__(self, x: complex) -> complex: ... def __radd__(self, x: complex) -> complex: ... def __rsub__(self, x: complex) -> complex: ... def __rmul__(self, x: complex) -> complex: ... def __rpow__(self, x: complex) -> complex: ... + if sys.version_info < (3,): + def __rdiv__(self, x: complex) -> complex: ... def __rtruediv__(self, x: complex) -> complex: ... def __eq__(self, x: object) -> bool: ... @@ -245,184 +279,361 @@ class complex: def __complex__(self) -> complex: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... - def __bool__(self) -> bool: ... + if sys.version_info >= (3,): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... -class str(Sequence[str]): - @overload - def __init__(self, o: object = ...) -> None: ... - @overload - def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ... +if sys.version_info >= (3,): + _str_base = object +else: + class basestring(metaclass=ABCMeta): ... + + class unicode(basestring, Sequence[unicode]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... + def capitalize(self) -> unicode: ... + def center(self, width: int, fillchar: unicode = ...) -> unicode: ... + def count(self, x: unicode) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> unicode: ... + def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> unicode: ... + def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... + def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def isidentifier(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[unicode]) -> unicode: ... + def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def lower(self) -> unicode: ... + def lstrip(self, chars: unicode = ...) -> unicode: ... + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... + def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def rstrip(self, chars: unicode = ...) -> unicode: ... + def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[unicode]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def strip(self, chars: unicode = ...) -> unicode: ... + def swapcase(self) -> unicode: ... + def title(self) -> unicode: ... + def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... + def upper(self) -> unicode: ... + def zfill(self, width: int) -> unicode: ... + + @overload + def __getitem__(self, i: int) -> unicode: ... + @overload + def __getitem__(self, s: slice) -> unicode: ... + def __getslice__(self, start: int, stop: int) -> unicode: ... + def __add__(self, s: unicode) -> unicode: ... + def __mul__(self, n: int) -> unicode: ... + def __rmul__(self, n: int) -> unicode: ... + def __mod__(self, x: Any) -> unicode: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: unicode) -> bool: ... + def __le__(self, x: unicode) -> bool: ... + def __gt__(self, x: unicode) -> bool: ... + def __ge__(self, x: unicode) -> bool: ... + + def __len__(self) -> int: ... + def __contains__(self, s: object) -> bool: ... + def __iter__(self) -> Iterator[unicode]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + + _str_base = basestring + +class str(Sequence[str], _str_base): + if sys.version_info >= (3,): + @overload + def __init__(self, o: object = ...) -> None: ... + @overload + def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ... + else: + def __init__(self, o: object = ...) -> None: ... def capitalize(self) -> str: ... - def casefold(self) -> str: ... + if sys.version_info >= (3, 3): + def casefold(self) -> str: ... def center(self, width: int, fillchar: str = ...) -> str: ... - def count(self, x: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ... - def endswith(self, suffix: Union[str, Tuple[str, ...]], start: Optional[int] = ..., - end: Optional[int] = ...) -> bool: ... + def count(self, x: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info < (3,): + def decode(self, encoding: Text = ..., errors: Text = ...) -> unicode: ... + def encode(self, encoding: Text = ..., errors: Text = ...) -> bytes: ... + if sys.version_info >= (3,): + def endswith(self, suffix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + else: + def endswith(self, suffix: Union[Text, Tuple[Text, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> str: ... - def find(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def format(self, *args: Any, **kwargs: Any) -> str: ... - def format_map(self, map: Mapping[str, Any]) -> str: ... - def index(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def format_map(self, map: Mapping[str, Any]) -> str: ... + def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... - def isdecimal(self) -> bool: ... + if sys.version_info >= (3,): + def isdecimal(self) -> bool: ... def isdigit(self) -> bool: ... - def isidentifier(self) -> bool: ... + if sys.version_info >= (3,): + def isidentifier(self) -> bool: ... def islower(self) -> bool: ... - def isnumeric(self) -> bool: ... - def isprintable(self) -> bool: ... + if sys.version_info >= (3,): + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[str]) -> str: ... + if sys.version_info >= (3,): + def join(self, iterable: Iterable[str]) -> str: ... + else: + def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... def ljust(self, width: int, fillchar: str = ...) -> str: ... def lower(self) -> str: ... - def lstrip(self, chars: Optional[str] = ...) -> str: ... - def partition(self, sep: str) -> Tuple[str, str, str]: ... - def replace(self, old: str, new: str, count: int = ...) -> str: ... - def rfind(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def rindex(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def lstrip(self, chars: Optional[str] = ...) -> str: ... + def partition(self, sep: str) -> Tuple[str, str, str]: ... + def replace(self, old: str, new: str, count: int = ...) -> str: ... + else: + @overload + def lstrip(self, chars: str = ...) -> str: ... + @overload + def lstrip(self, chars: unicode) -> unicode: ... + @overload + def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def partition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... + def rfind(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def rjust(self, width: int, fillchar: str = ...) -> str: ... - def rpartition(self, sep: str) -> Tuple[str, str, str]: ... - def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - def rstrip(self, chars: Optional[str] = ...) -> str: ... - def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + if sys.version_info >= (3,): + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + def rstrip(self, chars: Optional[str] = ...) -> str: ... + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + else: + @overload + def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + @overload + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + @overload + def rstrip(self, chars: str = ...) -> str: ... + @overload + def rstrip(self, chars: unicode) -> unicode: ... + @overload + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... def splitlines(self, keepends: bool = ...) -> List[str]: ... - def startswith(self, prefix: Union[str, Tuple[str, ...]], start: Optional[int] = ..., - end: Optional[int] = ...) -> bool: ... - def strip(self, chars: Optional[str] = ...) -> str: ... + if sys.version_info >= (3,): + def startswith(self, prefix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + def strip(self, chars: Optional[str] = ...) -> str: ... + else: + def startswith(self, prefix: Union[Text, Tuple[Text, ...]]) -> bool: ... + @overload + def strip(self, chars: str = ...) -> str: ... + @overload + def strip(self, chars: unicode) -> unicode: ... def swapcase(self) -> str: ... def title(self) -> str: ... - def translate(self, table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ... + if sys.version_info >= (3,): + def translate(self, table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ... + else: + def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... def upper(self) -> str: ... def zfill(self, width: int) -> str: ... - @staticmethod - @overload - def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... - @staticmethod - @overload - def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... - + if sys.version_info >= (3,): + @staticmethod + @overload + def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... + @staticmethod + @overload + def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... + + if sys.version_info >= (3,): + def __add__(self, s: str) -> str: ... + else: + def __add__(self, s: AnyStr) -> AnyStr: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ge__(self, x: Text) -> bool: ... def __getitem__(self, i: Union[int, slice]) -> str: ... - def __add__(self, s: str) -> str: ... + def __gt__(self, x: Text) -> bool: ... + def __hash__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + def __le__(self, x: Text) -> bool: ... + def __len__(self) -> int: ... + def __lt__(self, x: Text) -> bool: ... + def __mod__(self, x: Any) -> str: ... def __mul__(self, n: int) -> str: ... - def __rmul__(self, n: int) -> str: ... - def __mod__(self, value: Any) -> str: ... - def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: str) -> bool: ... - def __le__(self, x: str) -> bool: ... - def __gt__(self, x: str) -> bool: ... - def __ge__(self, x: str) -> bool: ... - - def __len__(self) -> int: ... - def __contains__(self, s: object) -> bool: ... - def __iter__(self) -> Iterator[str]: ... - def __str__(self) -> str: ... def __repr__(self) -> str: ... - def __hash__(self) -> int: ... - -class bytes(ByteString): - @overload - def __init__(self, ints: Iterable[int]) -> None: ... - @overload - def __init__(self, string: str, encoding: str, - errors: str = ...) -> None: ... - @overload - def __init__(self, length: int) -> None: ... - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, o: SupportsBytes) -> None: ... - def capitalize(self) -> bytes: ... - def center(self, width: int, fillchar: bytes = ...) -> bytes: ... - def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def decode(self, encoding: str = ..., errors: str = ...) -> str: ... - def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... - def expandtabs(self, tabsize: int = ...) -> bytes: ... - def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - if sys.version_info >= (3, 5): - def hex(self) -> str: ... - def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def isalnum(self) -> bool: ... - def isalpha(self) -> bool: ... - def isdigit(self) -> bool: ... - def islower(self) -> bool: ... - def isspace(self) -> bool: ... - def istitle(self) -> bool: ... - def isupper(self) -> bool: ... - def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytes: ... - def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... - def lower(self) -> bytes: ... - def lstrip(self, chars: Optional[bytes] = ...) -> bytes: ... - def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... - def replace(self, old: bytes, new: bytes, count: int = ...) -> bytes: ... - def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... - def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... - def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... - def rstrip(self, chars: Optional[bytes] = ...) -> bytes: ... - def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... - def splitlines(self, keepends: bool = ...) -> List[bytes]: ... - def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... - def strip(self, chars: Optional[bytes] = ...) -> bytes: ... - def swapcase(self) -> bytes: ... - def title(self) -> bytes: ... - def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ... - def upper(self) -> bytes: ... - def zfill(self, width: int) -> bytes: ... - @classmethod - def fromhex(cls, s: str) -> bytes: ... - @classmethod - def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... - - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[int]: ... + def __rmul__(self, n: int) -> str: ... def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... - @overload - def __getitem__(self, i: int) -> int: ... - @overload - def __getitem__(self, s: slice) -> bytes: ... - def __add__(self, s: bytes) -> bytes: ... - def __mul__(self, n: int) -> bytes: ... - def __rmul__(self, n: int) -> bytes: ... - if sys.version_info >= (3, 5): - def __mod__(self, value: Any) -> bytes: ... - def __contains__(self, o: object) -> bool: ... - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: bytes) -> bool: ... - def __le__(self, x: bytes) -> bool: ... - def __gt__(self, x: bytes) -> bool: ... - def __ge__(self, x: bytes) -> bool: ... + + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> str: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + +if sys.version_info >= (3,): + class bytes(ByteString): + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str, encoding: str, + errors: str = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: SupportsBytes) -> None: ... + def capitalize(self) -> bytes: ... + def center(self, width: int, fillchar: bytes = ...) -> bytes: ... + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def decode(self, encoding: str = ..., errors: str = ...) -> str: ... + def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> bytes: ... + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytes: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def lower(self) -> bytes: ... + def lstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def replace(self, old: bytes, new: bytes, count: int = ...) -> bytes: ... + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def rstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def splitlines(self, keepends: bool = ...) -> List[bytes]: ... + def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def strip(self, chars: Optional[bytes] = ...) -> bytes: ... + def swapcase(self) -> bytes: ... + def title(self) -> bytes: ... + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ... + def upper(self) -> bytes: ... + def zfill(self, width: int) -> bytes: ... + @classmethod + def fromhex(cls, s: str) -> bytes: ... + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> bytes: ... + def __add__(self, s: bytes) -> bytes: ... + def __mul__(self, n: int) -> bytes: ... + def __rmul__(self, n: int) -> bytes: ... + if sys.version_info >= (3, 5): + def __mod__(self, value: Any) -> bytes: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: bytes) -> bool: ... + def __le__(self, x: bytes) -> bool: ... + def __gt__(self, x: bytes) -> bool: ... + def __ge__(self, x: bytes) -> bool: ... +else: + bytes = str class bytearray(MutableSequence[int], ByteString): - @overload - def __init__(self, ints: Iterable[int]) -> None: ... - @overload - def __init__(self, string: str, encoding: str, errors: str = ...) -> None: ... - @overload - def __init__(self, length: int) -> None: ... - @overload - def __init__(self) -> None: ... + if sys.version_info >= (3,): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + else: + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str) -> None: ... + @overload + def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... def capitalize(self) -> bytearray: ... def center(self, width: int, fillchar: bytes = ...) -> bytearray: ... - def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def copy(self) -> bytearray: ... - def decode(self, encoding: str = ..., errors: str = ...) -> str: ... - def endswith(self, suffix: bytes) -> bool: ... + if sys.version_info >= (3,): + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def copy(self) -> bytearray: ... + else: + def count(self, x: str) -> int: ... + def decode(self, encoding: Text = ..., errors: Text = ...) -> str: ... + def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytearray: ... - def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - if sys.version_info >= (3, 5): - def hex(self) -> str: ... - def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + else: + def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... def insert(self, index: int, object: int) -> None: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -431,31 +642,43 @@ class bytearray(MutableSequence[int], ByteString): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytearray: ... - def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + if sys.version_info >= (3,): + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytearray: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + else: + def join(self, iterable: Iterable[str]) -> bytearray: ... + def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... def lower(self) -> bytearray: ... def lstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... def replace(self, old: bytes, new: bytes, count: int = ...) -> bytearray: ... - def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3,): + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + else: + def rfind(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ... def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... def rstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... - def startswith(self, prefix: bytes) -> bool: ... + def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def strip(self, chars: Optional[bytes] = ...) -> bytearray: ... def swapcase(self) -> bytearray: ... def title(self) -> bytearray: ... - def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ... + if sys.version_info >= (3,): + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ... + else: + def translate(self, table: str) -> bytearray: ... def upper(self) -> bytearray: ... def zfill(self, width: int) -> bytearray: ... - @classmethod - def fromhex(cls, s: str) -> bytearray: ... - @classmethod - def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... + @staticmethod + def fromhex(s: str) -> bytearray: ... + if sys.version_info >= (3,): + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ... @@ -473,11 +696,17 @@ class bytearray(MutableSequence[int], ByteString): @overload def __setitem__(self, s: slice, x: Union[Iterable[int], bytes]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> bytearray: ... + def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self, s: bytes) -> bytearray: ... - def __iadd__(self, s: Iterable[int]) -> bytearray: ... + if sys.version_info >= (3,): + def __iadd__(self, s: Iterable[int]) -> bytearray: ... def __mul__(self, n: int) -> bytearray: ... - def __rmul__(self, n: int) -> bytearray: ... - def __imul__(self, n: int) -> bytearray: ... + if sys.version_info >= (3,): + def __rmul__(self, n: int) -> bytearray: ... + def __imul__(self, n: int) -> bytearray: ... if sys.version_info >= (3, 5): def __mod__(self, value: Any) -> bytes: ... def __contains__(self, o: object) -> bool: ... @@ -488,7 +717,12 @@ class bytearray(MutableSequence[int], ByteString): def __gt__(self, x: bytes) -> bool: ... def __ge__(self, x: bytes) -> bool: ... -class memoryview(Sized, Container[int]): +if sys.version_info >= (3,): + _mv_container_type = int +else: + _mv_container_type = str + +class memoryview(Sized, Container[_mv_container_type]): format = ... # type: str itemsize = ... # type: int shape = ... # type: Optional[Tuple[int, ...]] @@ -497,17 +731,20 @@ class memoryview(Sized, Container[int]): readonly = ... # type: bool ndim = ... # type: int - def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... - def __enter__(self) -> memoryview: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ... + if sys.version_info >= (3,): + def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... + def __enter__(self) -> memoryview: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ... + else: + def __init__(self, obj: Union[bytes, bytearray, buffer, memoryview]) -> None: ... @overload - def __getitem__(self, i: int) -> int: ... + def __getitem__(self, i: int) -> _mv_container_type: ... @overload def __getitem__(self, s: slice) -> memoryview: ... def __contains__(self, x: object) -> bool: ... - def __iter__(self) -> Iterator[int]: ... + def __iter__(self) -> Iterator[_mv_container_type]: ... def __len__(self) -> int: ... @overload @@ -550,7 +787,7 @@ class bool(int): @overload # type: ignore def __rxor__(self, x: int) -> int: ... -class slice: +class slice(object): start = ... # type: Optional[int] step = ... # type: Optional[int] stop = ... # type: Optional[int] @@ -585,18 +822,20 @@ class tuple(Sequence[_T_co], Generic[_T_co]): class function: # TODO not defined in builtins! __name__ = ... # type: str - __qualname__ = ... # type: str __module__ = ... # type: str - __code__ = ... # type: CodeType - __annotations__ = ... # type: Dict[str, Any] + if sys.version_info >= (3,): + __qualname__ = ... # type: str + __code__ = ... # type: CodeType + __annotations__ = ... # type: Dict[str, Any] class list(MutableSequence[_T], Generic[_T]): @overload def __init__(self) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... - def clear(self) -> None: ... - def copy(self) -> List[_T]: ... + if sys.version_info >= (3,): + def clear(self) -> None: ... + def copy(self) -> List[_T]: ... def append(self, object: _T) -> None: ... def extend(self, iterable: Iterable[_T]) -> None: ... def pop(self, index: int = ...) -> _T: ... @@ -605,7 +844,10 @@ class list(MutableSequence[_T], Generic[_T]): def insert(self, index: int, object: _T) -> None: ... def remove(self, object: _T) -> None: ... def reverse(self) -> None: ... - def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ... + if sys.version_info >= (3,): + def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ... + else: + def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... @@ -620,11 +862,16 @@ class list(MutableSequence[_T], Generic[_T]): @overload def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... + if sys.version_info < (3,): + def __getslice__(self, start: int, stop: int) -> List[_T]: ... + def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self, x: List[_T]) -> List[_T]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... - def __imul__(self, n: int) -> List[_T]: ... + if sys.version_info >= (3,): + def __imul__(self, n: int) -> List[_T]: ... def __contains__(self, o: object) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... def __gt__(self, x: List[_T]) -> bool: ... @@ -644,6 +891,8 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... + if sys.version_info < (3,): + def has_key(self, k: _KT) -> bool: ... def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... def popitem(self) -> Tuple[_KT, _VT]: ... @@ -654,9 +903,17 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... @overload def update(self, **kwargs: _VT) -> None: ... - def keys(self) -> KeysView[_KT]: ... - def values(self) -> ValuesView[_VT]: ... - def items(self) -> ItemsView[_KT, _VT]: ... + if sys.version_info >= (3,): + def keys(self) -> KeysView[_KT]: ... + def values(self) -> ValuesView[_VT]: ... + def items(self) -> ItemsView[_KT, _VT]: ... + else: + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def viewkeys(self) -> KeysView[_KT]: ... + def viewvalues(self) -> ValuesView[_VT]: ... + def viewitems(self) -> ItemsView[_KT, _VT]: ... @staticmethod @overload def fromkeys(seq: Iterable[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) @@ -675,10 +932,10 @@ class set(MutableSet[_T], Generic[_T]): def add(self, element: _T) -> None: ... def clear(self) -> None: ... def copy(self) -> Set[_T]: ... - def difference(self, *s: Iterable[object]) -> Set[_T]: ... - def difference_update(self, *s: Iterable[object]) -> None: ... + def difference(self, *s: Iterable[Any]) -> Set[_T]: ... + def difference_update(self, *s: Iterable[Any]) -> None: ... def discard(self, element: _T) -> None: ... - def intersection(self, *s: Iterable[object]) -> Set[_T]: ... + def intersection(self, *s: Iterable[Any]) -> Set[_T]: ... def intersection_update(self, *s: Iterable[Any]) -> None: ... def isdisjoint(self, s: Iterable[Any]) -> bool: ... def issubset(self, s: Iterable[Any]) -> bool: ... @@ -732,29 +989,44 @@ class frozenset(AbstractSet[_T], Generic[_T]): class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... def __iter__(self) -> Iterator[Tuple[int, _T]]: ... - def __next__(self) -> Tuple[int, _T]: ... - -class range(Sequence[int]): - start = ... # type: int - stop = ... # type: int - step = ... # type: int - @overload - def __init__(self, stop: int) -> None: ... - @overload - def __init__(self, start: int, stop: int, step: int = ...) -> None: ... - def count(self, value: int) -> int: ... - def index(self, value: int, start: int = ..., stop: Optional[int] = ...) -> int: ... - def __len__(self) -> int: ... - def __contains__(self, o: object) -> bool: ... - def __iter__(self) -> Iterator[int]: ... - @overload - def __getitem__(self, i: int) -> int: ... - @overload - def __getitem__(self, s: slice) -> range: ... - def __repr__(self) -> str: ... - def __reversed__(self) -> Iterator[int]: ... - -class property: + if sys.version_info >= (3,): + def __next__(self) -> Tuple[int, _T]: ... + else: + def next(self) -> Tuple[int, _T]: ... + # TODO __getattribute__ + +if sys.version_info >= (3,): + class range(Sequence[int]): + start = ... # type: int + stop = ... # type: int + step = ... # type: int + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def count(self, value: int) -> int: ... + def index(self, value: int, start: int = ..., stop: Optional[int] = ...) -> int: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[int]: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> range: ... + def __repr__(self) -> str: ... + def __reversed__(self) -> Iterator[int]: ... +else: + class xrange(Sized, Iterable[int], Reversible[int]): + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __getitem__(self, i: int) -> int: ... + def __reversed__(self) -> Iterator[int]: ... + +class property(object): def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., fset: Optional[Callable[[Any, Any], None]] = ..., fdel: Optional[Callable[[Any], None]] = ..., @@ -769,17 +1041,27 @@ class property: def fset(self, value: Any) -> None: ... def fdel(self) -> None: ... +if sys.version_info < (3,): + long = int + NotImplemented = ... # type: Any def abs(n: SupportsAbs[_T]) -> _T: ... def all(i: Iterable[object]) -> bool: ... def any(i: Iterable[object]) -> bool: ... -def ascii(o: object) -> str: ... +if sys.version_info < (3,): + def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... +if sys.version_info >= (3,): + def ascii(o: object) -> str: ... def bin(number: int) -> str: ... if sys.version_info >= (3, 7): def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(o: object) -> bool: ... def chr(code: int) -> str: ... +if sys.version_info < (3,): + def cmp(x: Any, y: Any) -> int: ... + _N1 = TypeVar('_N1', bool, int, float, complex) + def coerce(x: _N1, y: _N1) -> Tuple[_N1, _N1]: ... if sys.version_info >= (3, 6): # This class is to be exported as PathLike from os, # but we define it here as _PathLike to avoid import cycle issues. @@ -789,28 +1071,54 @@ if sys.version_info >= (3, 6): def compile(source: Any, filename: Union[str, bytes, _PathLike], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... else: def compile(source: Any, filename: Union[str, bytes], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... -def copyright() -> None: ... -def credits() -> None: ... -def delattr(o: Any, name: str) -> None: ... +if sys.version_info >= (3,): + def copyright() -> None: ... + def credits() -> None: ... +def delattr(o: Any, name: Text) -> None: ... def dir(o: object = ...) -> List[str]: ... -_N = TypeVar('_N', int, float) -def divmod(a: _N, b: _N) -> Tuple[_N, _N]: ... -def eval(source: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... -def exec(object: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +_N2 = TypeVar('_N2', int, float) +def divmod(a: _N2, b: _N2) -> Tuple[_N2, _N2]: ... +def eval(source: Union[Text, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +if sys.version_info >= (3,): + def exec(object: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +else: + def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... def exit(code: Any = ...) -> NoReturn: ... -@overload -def filter(function: None, iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... -@overload -def filter(function: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... -def format(o: object, format_spec: str = ...) -> str: ... -def getattr(o: Any, name: str, default: Any = ...) -> Any: ... +if sys.version_info >= (3,): + @overload + def filter(__function: None, __iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... + @overload + def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Iterator[_T]: ... +else: + @overload + def filter(__function: Callable[[AnyStr], Any], # type: ignore + __iterable: AnyStr) -> AnyStr: ... + @overload + def filter(__function: None, # type: ignore + __iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ... + @overload + def filter(__function: Callable[[_T], Any], # type: ignore + __iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ... + @overload + def filter(__function: None, + __iterable: Iterable[Optional[_T]]) -> List[_T]: ... + @overload + def filter(__function: Callable[[_T], Any], + __iterable: Iterable[_T]) -> List[_T]: ... +def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode +def getattr(o: Any, name: Text, default: Any = ...) -> Any: ... def globals() -> Dict[str, Any]: ... -def hasattr(o: Any, name: str) -> bool: ... +def hasattr(o: Any, name: Text) -> bool: ... def hash(o: object) -> int: ... -def help(*args: Any, **kwds: Any) -> None: ... +if sys.version_info >= (3,): + def help(*args: Any, **kwds: Any) -> None: ... def hex(i: int) -> str: ... # TODO __index__ def id(o: object) -> int: ... -def input(prompt: Optional[Any] = ...) -> str: ... +if sys.version_info >= (3,): + def input(prompt: Any = ...) -> str: ... +else: + def input(prompt: Any = ...) -> Any: ... + def intern(string: str) -> str: ... @overload def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... @overload @@ -818,48 +1126,129 @@ def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ... def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... def issubclass(cls: type, classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... def len(o: Sized) -> int: ... -def license() -> None: ... +if sys.version_info >= (3,): + def license() -> None: ... def locals() -> Dict[str, Any]: ... -@overload -def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... -@overload -def map(func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> Iterator[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> Iterator[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3, _T4], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> Iterator[_S]: ... -@overload -def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> Iterator[_S]: ... -@overload -def map(func: Callable[..., _S], - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> Iterator[_S]: ... -@overload -def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... -@overload -def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +if sys.version_info >= (3,): + @overload + def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> Iterator[_S]: ... + @overload + def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[_S]: ... +else: + @overload + def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... + @overload + def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... + @overload + def map(func: None, + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... + @overload + def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[_S]: ... + @overload + def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[_S]: ... + @overload + def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[_S]: ... +if sys.version_info >= (3,): + @overload + def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +else: + @overload + def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +if sys.version_info >= (3,): + @overload + def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +else: + @overload + def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... + @overload + def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... @overload def next(i: Iterator[_T]) -> _T: ... @overload @@ -869,12 +1258,18 @@ def oct(i: int) -> str: ... # TODO __index__ if sys.version_info >= (3, 6): def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... -else: +elif sys.version_info >= (3,): def open(file: Union[str, bytes, int], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... +else: + def open(file: Union[unicode, int], mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... -def ord(c: Union[str, bytes, bytearray]) -> int: ... -def print(*values: Any, sep: str = ..., end: str = ..., file: Optional[IO[str]] = ..., flush: bool = ...) -> None: ... +def ord(c: Union[str, bytes]) -> int: ... +if sys.version_info >= (3,): + def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[str]] = ..., flush: bool = ...) -> None: ... +else: + # This is only available after from __future__ import print_function. + def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[Any]] = ...) -> None: ... @overload def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y @overload @@ -884,159 +1279,246 @@ def pow(x: float, y: float) -> float: ... @overload def pow(x: float, y: float, z: float) -> float: ... def quit(code: Optional[int] = ...) -> None: ... +if sys.version_info < (3,): + def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... + def raw_input(prompt: Any = ...) -> str: ... + @overload + def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... + @overload + def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... + def reload(module: Any) -> Any: ... @overload def reversed(object: Sequence[_T]) -> Iterator[_T]: ... @overload def reversed(object: Reversible[_T]) -> Iterator[_T]: ... def repr(o: object) -> str: ... -@overload -def round(number: float) -> int: ... -@overload -def round(number: float, ndigits: None) -> int: ... -@overload -def round(number: float, ndigits: int) -> float: ... -@overload -def round(number: SupportsRound[_T]) -> int: ... -@overload -def round(number: SupportsRound[_T], ndigits: None) -> int: ... # type: ignore -@overload -def round(number: SupportsRound[_T], ndigits: int) -> _T: ... -def setattr(object: Any, name: str, value: Any) -> None: ... -def sorted(iterable: Iterable[_T], *, - key: Optional[Callable[[_T], Any]] = ..., - reverse: bool = ...) -> List[_T]: ... +if sys.version_info >= (3,): + @overload + def round(number: float) -> int: ... + @overload + def round(number: float, ndigits: None) -> int: ... + @overload + def round(number: float, ndigits: int) -> float: ... + @overload + def round(number: SupportsRound[_T]) -> int: ... + @overload + def round(number: SupportsRound[_T], ndigits: None) -> int: ... # type: ignore + @overload + def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +else: + @overload + def round(number: float) -> float: ... + @overload + def round(number: float, ndigits: int) -> float: ... + @overload + def round(number: SupportsRound[_T]) -> _T: ... + @overload + def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +def setattr(object: Any, name: Text, value: Any) -> None: ... +if sys.version_info >= (3,): + def sorted(iterable: Iterable[_T], *, + key: Optional[Callable[[_T], Any]] = ..., + reverse: bool = ...) -> List[_T]: ... +else: + def sorted(iterable: Iterable[_T], *, + cmp: Callable[[_T, _T], int] = ..., + key: Callable[[_T], Any] = ..., + reverse: bool = ...) -> List[_T]: ... @overload def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... @overload def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... +if sys.version_info < (3,): + def unichr(i: int) -> unicode: ... def vars(object: Any = ...) -> Dict[str, Any]: ... -@overload -def zip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, +if sys.version_info >= (3,): + @overload + def zip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... + @overload + def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... +else: + @overload + def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... + @overload + def zip(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... -@overload -def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4], iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, + @overload + def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... -@overload -def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], - iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], - *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... -def __import__(name: str, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., + @overload + def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... +def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., fromlist: List[str] = ..., level: int = ...) -> Any: ... -# Ellipsis - # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. class ellipsis: ... Ellipsis = ... # type: ellipsis -# Exceptions +if sys.version_info < (3,): + # TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. + _AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) -class BaseException: + class buffer(Sized): + def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... + def __add__(self, other: _AnyBuffer) -> str: ... + def __cmp__(self, other: _AnyBuffer) -> bool: ... + def __getitem__(self, key: Union[int, slice]) -> str: ... + def __getslice__(self, i: int, j: int) -> str: ... + def __len__(self) -> int: ... + def __mul__(self, x: int) -> str: ... + +class BaseException(object): args = ... # type: Tuple[Any, ...] - __cause__ = ... # type: Optional[BaseException] - __context__ = ... # type: Optional[BaseException] - __traceback__ = ... # type: Optional[TracebackType] + if sys.version_info < (3,): + message = ... # type: Any + if sys.version_info >= (3,): + __cause__ = ... # type: Optional[BaseException] + __context__ = ... # type: Optional[BaseException] + __traceback__ = ... # type: Optional[TracebackType] def __init__(self, *args: object) -> None: ... - def with_traceback(self, tb: Optional[TracebackType]) -> BaseException: ... + if sys.version_info < (3,): + def __getitem__(self, i: int) -> Any: ... + def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... + if sys.version_info >= (3,): + def with_traceback(self, tb: Optional[TracebackType]) -> BaseException: ... class GeneratorExit(BaseException): ... class KeyboardInterrupt(BaseException): ... class SystemExit(BaseException): code = 0 class Exception(BaseException): ... -class ArithmeticError(Exception): ... -class OSError(Exception): - errno = 0 - strerror = ... # type: str - # filename, filename2 are actually Union[str, bytes, None] - filename = ... # type: Any - filename2 = ... # type: Any -IOError = OSError -EnvironmentError = OSError -class WindowsError(OSError): - winerror = ... # type: int -class LookupError(Exception): ... -class RuntimeError(Exception): ... -class ValueError(Exception): ... -class AssertionError(Exception): ... -class AttributeError(Exception): ... -class BufferError(Exception): ... -class EOFError(Exception): ... -class FloatingPointError(ArithmeticError): ... -class ImportError(Exception): - name = ... # type: str - path = ... # type: str -if sys.version_info >= (3, 6): - class ModuleNotFoundError(ImportError): ... -class IndexError(LookupError): ... -class KeyError(LookupError): ... -class MemoryError(Exception): ... -class NameError(Exception): ... -class NotImplementedError(RuntimeError): ... -class BlockingIOError(OSError): - characters_written = 0 -class ChildProcessError(OSError): ... -class ConnectionError(OSError): ... -class BrokenPipeError(ConnectionError): ... -class ConnectionAbortedError(ConnectionError): ... -class ConnectionRefusedError(ConnectionError): ... -class ConnectionResetError(ConnectionError): ... -class FileExistsError(OSError): ... -class FileNotFoundError(OSError): ... -class InterruptedError(OSError): ... -class IsADirectoryError(OSError): ... -class NotADirectoryError(OSError): ... -class PermissionError(OSError): ... -class ProcessLookupError(OSError): ... -class TimeoutError(OSError): ... -class OverflowError(ArithmeticError): ... -class ReferenceError(Exception): ... -class StopIteration(Exception): - value = ... # type: Any +class StopIteration(Exception): ... +if sys.version_info >= (3,): + _StandardError = Exception + class OSError(Exception): + errno = 0 + strerror = ... # type: str + # filename, filename2 are actually Union[str, bytes, None] + filename = ... # type: Any + filename2 = ... # type: Any + EnvironmentError = OSError + IOError = OSError +else: + class StandardError(Exception): ... + _StandardError = StandardError + class EnvironmentError(StandardError): + errno = 0 + strerror = ... # type: str + # TODO can this be unicode? + filename = ... # type: str + class OSError(EnvironmentError): ... + class IOError(EnvironmentError): ... + +class ArithmeticError(_StandardError): ... +class AssertionError(_StandardError): ... +class AttributeError(_StandardError): ... +class BufferError(_StandardError): ... +class EOFError(_StandardError): ... +class ImportError(_StandardError): + if sys.version_info >= (3,): + name = ... # type: str + path = ... # type: str +class LookupError(_StandardError): ... +class MemoryError(_StandardError): ... +class NameError(_StandardError): ... +class ReferenceError(_StandardError): ... +class RuntimeError(_StandardError): ... if sys.version_info >= (3, 5): class StopAsyncIteration(Exception): value = ... # type: Any - class RecursionError(RuntimeError): ... -class SyntaxError(Exception): +class SyntaxError(_StandardError): msg = ... # type: str lineno = ... # type: int offset = ... # type: int text = ... # type: str filename = ... # type: str +class SystemError(_StandardError): ... +class TypeError(_StandardError): ... +class ValueError(_StandardError): ... + +class FloatingPointError(ArithmeticError): ... +class OverflowError(ArithmeticError): ... +class ZeroDivisionError(ArithmeticError): ... + +if sys.version_info >= (3, 6): + class ModuleNotFoundError(ImportError): ... + +class IndexError(LookupError): ... +class KeyError(LookupError): ... + +class UnboundLocalError(NameError): ... + +class WindowsError(OSError): + winerror = ... # type: int +if sys.version_info >= (3,): + class BlockingIOError(OSError): + characters_written = 0 + class ChildProcessError(OSError): ... + class ConnectionError(OSError): ... + class BrokenPipeError(ConnectionError): ... + class ConnectionAbortedError(ConnectionError): ... + class ConnectionRefusedError(ConnectionError): ... + class ConnectionResetError(ConnectionError): ... + class FileExistsError(OSError): ... + class FileNotFoundError(OSError): ... + class InterruptedError(OSError): ... + class IsADirectoryError(OSError): ... + class NotADirectoryError(OSError): ... + class PermissionError(OSError): ... + class ProcessLookupError(OSError): ... + class TimeoutError(OSError): ... + +class NotImplementedError(RuntimeError): ... +if sys.version_info >= (3, 5): + class RecursionError(RuntimeError): ... + class IndentationError(SyntaxError): ... class TabError(IndentationError): ... -class SystemError(Exception): ... -class TypeError(Exception): ... -class UnboundLocalError(NameError): ... + class UnicodeError(ValueError): ... class UnicodeDecodeError(UnicodeError): - encoding = ... # type: str - object = ... # type: bytes - start = ... # type: int - end = ... # type: int - reason = ... # type: str + encoding: str + object: bytes + start: int + end: int + reason: str def __init__(self, __encoding: str, __object: bytes, __start: int, __end: int, __reason: str) -> None: ... class UnicodeEncodeError(UnicodeError): - encoding = ... # type: str - object = ... # type: str - start = ... # type: int - end = ... # type: int - reason = ... # type: str - def __init__(self, __encoding: str, __object: str, __start: int, __end: int, + encoding: str + object: Text + start: int + end: int + reason: str + def __init__(self, __encoding: str, __object: Text, __start: int, __end: int, __reason: str) -> None: ... class UnicodeTranslateError(UnicodeError): ... -class ZeroDivisionError(ArithmeticError): ... class Warning(Exception): ... class UserWarning(Warning): ... @@ -1048,4 +1530,34 @@ class PendingDeprecationWarning(Warning): ... class ImportWarning(Warning): ... class UnicodeWarning(Warning): ... class BytesWarning(Warning): ... -class ResourceWarning(Warning): ... +if sys.version_info >= (3, 2): + class ResourceWarning(Warning): ... + +if sys.version_info < (3,): + class file(BinaryIO): + @overload + def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def next(self) -> str: ... + def read(self, n: int = ...) -> str: ... + def __enter__(self) -> BinaryIO: ... + def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... + def flush(self) -> None: ... + def fileno(self) -> int: ... + def isatty(self) -> bool: ... + def close(self) -> None: ... + + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def seekable(self) -> bool: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + def readline(self, limit: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def write(self, data: str) -> int: ... + def writelines(self, data: Iterable[str]) -> None: ... + def truncate(self, pos: Optional[int] = ...) -> int: ... From bb2179b4b577b99f5623fa84221e301f72ec4da1 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 21 Oct 2018 21:00:10 +0200 Subject: [PATCH 2/9] Moved builtins.pyi to 2and3 --- stdlib/{2 => 2and3}/builtins.pyi | 0 stdlib/3/builtins.pyi | 1563 ------------------------------ tests/check_consistent.py | 2 +- 3 files changed, 1 insertion(+), 1564 deletions(-) rename stdlib/{2 => 2and3}/builtins.pyi (100%) delete mode 100644 stdlib/3/builtins.pyi diff --git a/stdlib/2/builtins.pyi b/stdlib/2and3/builtins.pyi similarity index 100% rename from stdlib/2/builtins.pyi rename to stdlib/2and3/builtins.pyi diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi deleted file mode 100644 index cda0a31616b3..000000000000 --- a/stdlib/3/builtins.pyi +++ /dev/null @@ -1,1563 +0,0 @@ -# True and False are deliberately omitted because they are keywords in -# Python 3, and stub files conform to Python 3 syntax. - -from typing import ( - TypeVar, Iterator, Iterable, NoReturn, overload, Container, - Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic, - Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, - SupportsComplex, SupportsRound, IO, BinaryIO, Union, - ItemsView, KeysView, ValuesView, ByteString, Optional, AnyStr, Type, Text, -) -from abc import abstractmethod, ABCMeta -from types import TracebackType, CodeType -import sys - -if sys.version_info >= (3,): - from typing import SupportsBytes - -_T = TypeVar('_T') -_T_co = TypeVar('_T_co', covariant=True) -_KT = TypeVar('_KT') -_VT = TypeVar('_VT') -_S = TypeVar('_S') -_T1 = TypeVar('_T1') -_T2 = TypeVar('_T2') -_T3 = TypeVar('_T3') -_T4 = TypeVar('_T4') -_T5 = TypeVar('_T5') -_TT = TypeVar('_TT', bound='type') - -class object: - __doc__ = ... # type: Optional[str] - __dict__ = ... # type: Dict[str, Any] - __slots__ = ... # type: Union[Text, Iterable[Text]] - __module__ = ... # type: str - if sys.version_info >= (3, 6): - __annotations__ = ... # type: Dict[str, Any] - - @property - def __class__(self: _T) -> Type[_T]: ... - @__class__.setter - def __class__(self, __type: Type[object]) -> None: ... - def __init__(self) -> None: ... - def __new__(cls) -> Any: ... - def __setattr__(self, name: str, value: Any) -> None: ... - def __eq__(self, o: object) -> bool: ... - def __ne__(self, o: object) -> bool: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __hash__(self) -> int: ... - def __format__(self, format_spec: str) -> str: ... - def __getattribute__(self, name: str) -> Any: ... - def __delattr__(self, name: str) -> None: ... - def __sizeof__(self) -> int: ... - def __reduce__(self) -> tuple: ... - def __reduce_ex__(self, protocol: int) -> tuple: ... - if sys.version_info >= (3,): - def __dir__(self) -> Iterable[str]: ... - if sys.version_info >= (3, 6): - def __init_subclass__(cls) -> None: ... - -class staticmethod(object): # Special, only valid as a decorator. - __func__ = ... # type: function - if sys.version_info >= (3,): - __isabstractmethod__ = ... # type: bool - - def __init__(self, f: function) -> None: ... - def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... - -class classmethod(object): # Special, only valid as a decorator. - __func__ = ... # type: function - if sys.version_info >= (3,): - __isabstractmethod__ = ... # type: bool - - def __init__(self, f: function) -> None: ... - def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... - -class type(object): - __bases__ = ... # type: Tuple[type, ...] - __name__ = ... # type: str - __module__ = ... # type: str - if sys.version_info >= (3,): - __qualname__ = ... # type: str - __dict__ = ... # type: Dict[str, Any] - __mro__ = ... # type: Tuple[type, ...] - - @overload - def __init__(self, o: object) -> None: ... - @overload - def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... - @overload - def __new__(cls, o: object) -> type: ... - @overload - def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... - def __call__(self, *args: Any, **kwds: Any) -> Any: ... - def __subclasses__(self: _TT) -> List[_TT]: ... - if sys.version_info < (3,): - # Only new-style classes - __mro__ = ... # type: Tuple[type, ...] - # Note: the documentation doesnt specify what the return type is, the standard - # implementation seems to be returning a list. - def mro(self) -> List[type]: ... - def __instancecheck__(self, instance: Any) -> bool: ... - def __subclasscheck__(self, subclass: type) -> bool: ... - -class super(object): - if sys.version_info >= (3,): - @overload - def __init__(self, t: Any, obj: Any) -> None: ... - @overload - def __init__(self, t: Any) -> None: ... - @overload - def __init__(self) -> None: ... - else: - @overload - def __init__(self, t: Any, obj: Any) -> None: ... - @overload - def __init__(self, t: Any) -> None: ... - -class int: - @overload - def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ... - @overload - def __init__(self, x: Union[Text, bytes, bytearray], base: int) -> None: ... - - def bit_length(self) -> int: ... - if sys.version_info >= (3,): - def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ... - @classmethod - def from_bytes(cls, bytes: Sequence[int], byteorder: str, *, - signed: bool = ...) -> int: ... # TODO buffer object argument - - def __add__(self, x: int) -> int: ... - def __sub__(self, x: int) -> int: ... - def __mul__(self, x: int) -> int: ... - def __floordiv__(self, x: int) -> int: ... - if sys.version_info < (3,): - def __div__(self, x: int) -> int: ... - def __truediv__(self, x: int) -> float: ... - def __mod__(self, x: int) -> int: ... - def __divmod__(self, x: int) -> Tuple[int, int]: ... - def __radd__(self, x: int) -> int: ... - def __rsub__(self, x: int) -> int: ... - def __rmul__(self, x: int) -> int: ... - def __rfloordiv__(self, x: int) -> int: ... - if sys.version_info < (3,): - def __rdiv__(self, x: int) -> int: ... - def __rtruediv__(self, x: int) -> float: ... - def __rmod__(self, x: int) -> int: ... - def __rdivmod__(self, x: int) -> Tuple[int, int]: ... - def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. - def __rpow__(self, x: int) -> Any: ... - def __and__(self, n: int) -> int: ... - def __or__(self, n: int) -> int: ... - def __xor__(self, n: int) -> int: ... - def __lshift__(self, n: int) -> int: ... - def __rshift__(self, n: int) -> int: ... - def __rand__(self, n: int) -> int: ... - def __ror__(self, n: int) -> int: ... - def __rxor__(self, n: int) -> int: ... - def __rlshift__(self, n: int) -> int: ... - def __rrshift__(self, n: int) -> int: ... - def __neg__(self) -> int: ... - def __pos__(self) -> int: ... - def __invert__(self) -> int: ... - if sys.version_info >= (3,): - def __round__(self, ndigits: Optional[int] = ...) -> int: ... - - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: int) -> bool: ... - def __le__(self, x: int) -> bool: ... - def __gt__(self, x: int) -> bool: ... - def __ge__(self, x: int) -> bool: ... - - def __str__(self) -> str: ... - def __float__(self) -> float: ... - def __int__(self) -> int: ... - def __abs__(self) -> int: ... - def __hash__(self) -> int: ... - if sys.version_info >= (3,): - def __bool__(self) -> bool: ... - else: - def __nonzero__(self) -> bool: ... - def __index__(self) -> int: ... - -class float: - def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ... - def as_integer_ratio(self) -> Tuple[int, int]: ... - def hex(self) -> str: ... - def is_integer(self) -> bool: ... - @classmethod - def fromhex(cls, s: str) -> float: ... - - def __add__(self, x: float) -> float: ... - def __sub__(self, x: float) -> float: ... - def __mul__(self, x: float) -> float: ... - def __floordiv__(self, x: float) -> float: ... - if sys.version_info < (3,): - def __div__(self, x: float) -> float: ... - def __truediv__(self, x: float) -> float: ... - def __mod__(self, x: float) -> float: ... - def __divmod__(self, x: float) -> Tuple[float, float]: ... - def __pow__(self, x: float) -> float: ... - def __radd__(self, x: float) -> float: ... - def __rsub__(self, x: float) -> float: ... - def __rmul__(self, x: float) -> float: ... - def __rfloordiv__(self, x: float) -> float: ... - if sys.version_info < (3,): - def __rdiv__(self, x: float) -> float: ... - def __rtruediv__(self, x: float) -> float: ... - def __rmod__(self, x: float) -> float: ... - def __rdivmod__(self, x: float) -> Tuple[float, float]: ... - def __rpow__(self, x: float) -> float: ... - if sys.version_info >= (3,): - @overload - def __round__(self) -> int: ... - @overload - def __round__(self, ndigits: None) -> int: ... - @overload - def __round__(self, ndigits: int) -> float: ... - - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: float) -> bool: ... - def __le__(self, x: float) -> bool: ... - def __gt__(self, x: float) -> bool: ... - def __ge__(self, x: float) -> bool: ... - def __neg__(self) -> float: ... - def __pos__(self) -> float: ... - - def __str__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __abs__(self) -> float: ... - def __hash__(self) -> int: ... - if sys.version_info >= (3,): - def __bool__(self) -> bool: ... - else: - def __nonzero__(self) -> bool: ... - -class complex: - @overload - def __init__(self, re: float = ..., im: float = ...) -> None: ... - @overload - def __init__(self, s: str) -> None: ... - @overload - def __init__(self, s: SupportsComplex) -> None: ... - - @property - def real(self) -> float: ... - @property - def imag(self) -> float: ... - - def conjugate(self) -> complex: ... - - def __add__(self, x: complex) -> complex: ... - def __sub__(self, x: complex) -> complex: ... - def __mul__(self, x: complex) -> complex: ... - def __pow__(self, x: complex) -> complex: ... - if sys.version_info < (3,): - def __div__(self, x: complex) -> complex: ... - def __truediv__(self, x: complex) -> complex: ... - def __radd__(self, x: complex) -> complex: ... - def __rsub__(self, x: complex) -> complex: ... - def __rmul__(self, x: complex) -> complex: ... - def __rpow__(self, x: complex) -> complex: ... - if sys.version_info < (3,): - def __rdiv__(self, x: complex) -> complex: ... - def __rtruediv__(self, x: complex) -> complex: ... - - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __neg__(self) -> complex: ... - def __pos__(self) -> complex: ... - - def __str__(self) -> str: ... - def __complex__(self) -> complex: ... - def __abs__(self) -> float: ... - def __hash__(self) -> int: ... - if sys.version_info >= (3,): - def __bool__(self) -> bool: ... - else: - def __nonzero__(self) -> bool: ... - -if sys.version_info >= (3,): - _str_base = object -else: - class basestring(metaclass=ABCMeta): ... - - class unicode(basestring, Sequence[unicode]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, o: object) -> None: ... - @overload - def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... - def capitalize(self) -> unicode: ... - def center(self, width: int, fillchar: unicode = ...) -> unicode: ... - def count(self, x: unicode) -> int: ... - def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... - def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... - def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., - end: int = ...) -> bool: ... - def expandtabs(self, tabsize: int = ...) -> unicode: ... - def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> unicode: ... - def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... - def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def isalnum(self) -> bool: ... - def isalpha(self) -> bool: ... - def isdecimal(self) -> bool: ... - def isdigit(self) -> bool: ... - def isidentifier(self) -> bool: ... - def islower(self) -> bool: ... - def isnumeric(self) -> bool: ... - def isprintable(self) -> bool: ... - def isspace(self) -> bool: ... - def istitle(self) -> bool: ... - def isupper(self) -> bool: ... - def join(self, iterable: Iterable[unicode]) -> unicode: ... - def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... - def lower(self) -> unicode: ... - def lstrip(self, chars: unicode = ...) -> unicode: ... - def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... - def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... - def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... - def rstrip(self, chars: unicode = ...) -> unicode: ... - def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... - def splitlines(self, keepends: bool = ...) -> List[unicode]: ... - def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., - end: int = ...) -> bool: ... - def strip(self, chars: unicode = ...) -> unicode: ... - def swapcase(self) -> unicode: ... - def title(self) -> unicode: ... - def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... - def upper(self) -> unicode: ... - def zfill(self, width: int) -> unicode: ... - - @overload - def __getitem__(self, i: int) -> unicode: ... - @overload - def __getitem__(self, s: slice) -> unicode: ... - def __getslice__(self, start: int, stop: int) -> unicode: ... - def __add__(self, s: unicode) -> unicode: ... - def __mul__(self, n: int) -> unicode: ... - def __rmul__(self, n: int) -> unicode: ... - def __mod__(self, x: Any) -> unicode: ... - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: unicode) -> bool: ... - def __le__(self, x: unicode) -> bool: ... - def __gt__(self, x: unicode) -> bool: ... - def __ge__(self, x: unicode) -> bool: ... - - def __len__(self) -> int: ... - def __contains__(self, s: object) -> bool: ... - def __iter__(self) -> Iterator[unicode]: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... - - _str_base = basestring - -class str(Sequence[str], _str_base): - if sys.version_info >= (3,): - @overload - def __init__(self, o: object = ...) -> None: ... - @overload - def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ... - else: - def __init__(self, o: object = ...) -> None: ... - - def capitalize(self) -> str: ... - if sys.version_info >= (3, 3): - def casefold(self) -> str: ... - def center(self, width: int, fillchar: str = ...) -> str: ... - def count(self, x: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - if sys.version_info < (3,): - def decode(self, encoding: Text = ..., errors: Text = ...) -> unicode: ... - def encode(self, encoding: Text = ..., errors: Text = ...) -> bytes: ... - if sys.version_info >= (3,): - def endswith(self, suffix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., - end: Optional[int] = ...) -> bool: ... - else: - def endswith(self, suffix: Union[Text, Tuple[Text, ...]]) -> bool: ... - def expandtabs(self, tabsize: int = ...) -> str: ... - def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> str: ... - if sys.version_info >= (3,): - def format_map(self, map: Mapping[str, Any]) -> str: ... - def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def isalnum(self) -> bool: ... - def isalpha(self) -> bool: ... - if sys.version_info >= (3,): - def isdecimal(self) -> bool: ... - def isdigit(self) -> bool: ... - if sys.version_info >= (3,): - def isidentifier(self) -> bool: ... - def islower(self) -> bool: ... - if sys.version_info >= (3,): - def isnumeric(self) -> bool: ... - def isprintable(self) -> bool: ... - def isspace(self) -> bool: ... - def istitle(self) -> bool: ... - def isupper(self) -> bool: ... - if sys.version_info >= (3,): - def join(self, iterable: Iterable[str]) -> str: ... - else: - def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... - def ljust(self, width: int, fillchar: str = ...) -> str: ... - def lower(self) -> str: ... - if sys.version_info >= (3,): - def lstrip(self, chars: Optional[str] = ...) -> str: ... - def partition(self, sep: str) -> Tuple[str, str, str]: ... - def replace(self, old: str, new: str, count: int = ...) -> str: ... - else: - @overload - def lstrip(self, chars: str = ...) -> str: ... - @overload - def lstrip(self, chars: unicode) -> unicode: ... - @overload - def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... - @overload - def partition(self, sep: str) -> Tuple[str, str, str]: ... - @overload - def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... - def rfind(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def rindex(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def rjust(self, width: int, fillchar: str = ...) -> str: ... - if sys.version_info >= (3,): - def rpartition(self, sep: str) -> Tuple[str, str, str]: ... - def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - def rstrip(self, chars: Optional[str] = ...) -> str: ... - def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - else: - @overload - def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... - @overload - def rpartition(self, sep: str) -> Tuple[str, str, str]: ... - @overload - def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... - @overload - def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - @overload - def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... - @overload - def rstrip(self, chars: str = ...) -> str: ... - @overload - def rstrip(self, chars: unicode) -> unicode: ... - @overload - def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... - @overload - def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... - def splitlines(self, keepends: bool = ...) -> List[str]: ... - if sys.version_info >= (3,): - def startswith(self, prefix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., - end: Optional[int] = ...) -> bool: ... - def strip(self, chars: Optional[str] = ...) -> str: ... - else: - def startswith(self, prefix: Union[Text, Tuple[Text, ...]]) -> bool: ... - @overload - def strip(self, chars: str = ...) -> str: ... - @overload - def strip(self, chars: unicode) -> unicode: ... - def swapcase(self) -> str: ... - def title(self) -> str: ... - if sys.version_info >= (3,): - def translate(self, table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ... - else: - def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... - def upper(self) -> str: ... - def zfill(self, width: int) -> str: ... - if sys.version_info >= (3,): - @staticmethod - @overload - def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... - @staticmethod - @overload - def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... - - if sys.version_info >= (3,): - def __add__(self, s: str) -> str: ... - else: - def __add__(self, s: AnyStr) -> AnyStr: ... - def __contains__(self, o: object) -> bool: ... - def __eq__(self, x: object) -> bool: ... - def __ge__(self, x: Text) -> bool: ... - def __getitem__(self, i: Union[int, slice]) -> str: ... - def __gt__(self, x: Text) -> bool: ... - def __hash__(self) -> int: ... - def __iter__(self) -> Iterator[str]: ... - def __le__(self, x: Text) -> bool: ... - def __len__(self) -> int: ... - def __lt__(self, x: Text) -> bool: ... - def __mod__(self, x: Any) -> str: ... - def __mul__(self, n: int) -> str: ... - def __ne__(self, x: object) -> bool: ... - def __repr__(self) -> str: ... - def __rmul__(self, n: int) -> str: ... - def __str__(self) -> str: ... - - if sys.version_info < (3,): - def __getslice__(self, start: int, stop: int) -> str: ... - def __float__(self) -> float: ... - def __int__(self) -> int: ... - -if sys.version_info >= (3,): - class bytes(ByteString): - @overload - def __init__(self, ints: Iterable[int]) -> None: ... - @overload - def __init__(self, string: str, encoding: str, - errors: str = ...) -> None: ... - @overload - def __init__(self, length: int) -> None: ... - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, o: SupportsBytes) -> None: ... - def capitalize(self) -> bytes: ... - def center(self, width: int, fillchar: bytes = ...) -> bytes: ... - def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def decode(self, encoding: str = ..., errors: str = ...) -> str: ... - def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... - def expandtabs(self, tabsize: int = ...) -> bytes: ... - def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - if sys.version_info >= (3, 5): - def hex(self) -> str: ... - def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def isalnum(self) -> bool: ... - def isalpha(self) -> bool: ... - def isdigit(self) -> bool: ... - def islower(self) -> bool: ... - def isspace(self) -> bool: ... - def istitle(self) -> bool: ... - def isupper(self) -> bool: ... - def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytes: ... - def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... - def lower(self) -> bytes: ... - def lstrip(self, chars: Optional[bytes] = ...) -> bytes: ... - def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... - def replace(self, old: bytes, new: bytes, count: int = ...) -> bytes: ... - def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... - def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... - def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... - def rstrip(self, chars: Optional[bytes] = ...) -> bytes: ... - def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... - def splitlines(self, keepends: bool = ...) -> List[bytes]: ... - def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... - def strip(self, chars: Optional[bytes] = ...) -> bytes: ... - def swapcase(self) -> bytes: ... - def title(self) -> bytes: ... - def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ... - def upper(self) -> bytes: ... - def zfill(self, width: int) -> bytes: ... - @classmethod - def fromhex(cls, s: str) -> bytes: ... - @classmethod - def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... - - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[int]: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... - @overload - def __getitem__(self, i: int) -> int: ... - @overload - def __getitem__(self, s: slice) -> bytes: ... - def __add__(self, s: bytes) -> bytes: ... - def __mul__(self, n: int) -> bytes: ... - def __rmul__(self, n: int) -> bytes: ... - if sys.version_info >= (3, 5): - def __mod__(self, value: Any) -> bytes: ... - def __contains__(self, o: object) -> bool: ... - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: bytes) -> bool: ... - def __le__(self, x: bytes) -> bool: ... - def __gt__(self, x: bytes) -> bool: ... - def __ge__(self, x: bytes) -> bool: ... -else: - bytes = str - -class bytearray(MutableSequence[int], ByteString): - if sys.version_info >= (3,): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, ints: Iterable[int]) -> None: ... - @overload - def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... - @overload - def __init__(self, length: int) -> None: ... - else: - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, ints: Iterable[int]) -> None: ... - @overload - def __init__(self, string: str) -> None: ... - @overload - def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ... - @overload - def __init__(self, length: int) -> None: ... - def capitalize(self) -> bytearray: ... - def center(self, width: int, fillchar: bytes = ...) -> bytearray: ... - if sys.version_info >= (3,): - def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def copy(self) -> bytearray: ... - else: - def count(self, x: str) -> int: ... - def decode(self, encoding: Text = ..., errors: Text = ...) -> str: ... - def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... - def expandtabs(self, tabsize: int = ...) -> bytearray: ... - if sys.version_info >= (3,): - def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - if sys.version_info >= (3, 5): - def hex(self) -> str: ... - def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - else: - def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... - def insert(self, index: int, object: int) -> None: ... - def isalnum(self) -> bool: ... - def isalpha(self) -> bool: ... - def isdigit(self) -> bool: ... - def islower(self) -> bool: ... - def isspace(self) -> bool: ... - def istitle(self) -> bool: ... - def isupper(self) -> bool: ... - if sys.version_info >= (3,): - def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytearray: ... - def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... - else: - def join(self, iterable: Iterable[str]) -> bytearray: ... - def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... - def lower(self) -> bytearray: ... - def lstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... - def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... - def replace(self, old: bytes, new: bytes, count: int = ...) -> bytearray: ... - if sys.version_info >= (3,): - def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... - else: - def rfind(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... - def rindex(self, sub: bytes, start: int = ..., end: int = ...) -> int: ... - def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ... - def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... - def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... - def rstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... - def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... - def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... - def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... - def strip(self, chars: Optional[bytes] = ...) -> bytearray: ... - def swapcase(self) -> bytearray: ... - def title(self) -> bytearray: ... - if sys.version_info >= (3,): - def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ... - else: - def translate(self, table: str) -> bytearray: ... - def upper(self) -> bytearray: ... - def zfill(self, width: int) -> bytearray: ... - @staticmethod - def fromhex(s: str) -> bytearray: ... - if sys.version_info >= (3,): - @classmethod - def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... - - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[int]: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... - def __hash__(self) -> int: ... - @overload - def __getitem__(self, i: int) -> int: ... - @overload - def __getitem__(self, s: slice) -> bytearray: ... - @overload - def __setitem__(self, i: int, x: int) -> None: ... - @overload - def __setitem__(self, s: slice, x: Union[Iterable[int], bytes]) -> None: ... - def __delitem__(self, i: Union[int, slice]) -> None: ... - if sys.version_info < (3,): - def __getslice__(self, start: int, stop: int) -> bytearray: ... - def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... - def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, s: bytes) -> bytearray: ... - if sys.version_info >= (3,): - def __iadd__(self, s: Iterable[int]) -> bytearray: ... - def __mul__(self, n: int) -> bytearray: ... - if sys.version_info >= (3,): - def __rmul__(self, n: int) -> bytearray: ... - def __imul__(self, n: int) -> bytearray: ... - if sys.version_info >= (3, 5): - def __mod__(self, value: Any) -> bytes: ... - def __contains__(self, o: object) -> bool: ... - def __eq__(self, x: object) -> bool: ... - def __ne__(self, x: object) -> bool: ... - def __lt__(self, x: bytes) -> bool: ... - def __le__(self, x: bytes) -> bool: ... - def __gt__(self, x: bytes) -> bool: ... - def __ge__(self, x: bytes) -> bool: ... - -if sys.version_info >= (3,): - _mv_container_type = int -else: - _mv_container_type = str - -class memoryview(Sized, Container[_mv_container_type]): - format = ... # type: str - itemsize = ... # type: int - shape = ... # type: Optional[Tuple[int, ...]] - strides = ... # type: Optional[Tuple[int, ...]] - suboffsets = ... # type: Optional[Tuple[int, ...]] - readonly = ... # type: bool - ndim = ... # type: int - - if sys.version_info >= (3,): - def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... - def __enter__(self) -> memoryview: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ... - else: - def __init__(self, obj: Union[bytes, bytearray, buffer, memoryview]) -> None: ... - - @overload - def __getitem__(self, i: int) -> _mv_container_type: ... - @overload - def __getitem__(self, s: slice) -> memoryview: ... - - def __contains__(self, x: object) -> bool: ... - def __iter__(self) -> Iterator[_mv_container_type]: ... - def __len__(self) -> int: ... - - @overload - def __setitem__(self, i: int, o: bytes) -> None: ... - @overload - def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... - @overload - def __setitem__(self, s: slice, o: memoryview) -> None: ... - - def tobytes(self) -> bytes: ... - def tolist(self) -> List[int]: ... - - if sys.version_info >= (3, 5): - def hex(self) -> str: ... - -class bool(int): - def __init__(self, o: object = ...) -> None: ... - @overload # type: ignore - def __and__(self, x: bool) -> bool: ... - @overload # type: ignore - def __and__(self, x: int) -> int: ... - @overload # type: ignore - def __or__(self, x: bool) -> bool: ... - @overload # type: ignore - def __or__(self, x: int) -> int: ... - @overload # type: ignore - def __xor__(self, x: bool) -> bool: ... - @overload # type: ignore - def __xor__(self, x: int) -> int: ... - @overload # type: ignore - def __rand__(self, x: bool) -> bool: ... - @overload # type: ignore - def __rand__(self, x: int) -> int: ... - @overload # type: ignore - def __ror__(self, x: bool) -> bool: ... - @overload # type: ignore - def __ror__(self, x: int) -> int: ... - @overload # type: ignore - def __rxor__(self, x: bool) -> bool: ... - @overload # type: ignore - def __rxor__(self, x: int) -> int: ... - -class slice(object): - start = ... # type: Optional[int] - step = ... # type: Optional[int] - stop = ... # type: Optional[int] - @overload - def __init__(self, stop: Optional[int]) -> None: ... - @overload - def __init__(self, start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> None: ... - def indices(self, len: int) -> Tuple[int, int, int]: ... - -class tuple(Sequence[_T_co], Generic[_T_co]): - def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T: ... - def __len__(self) -> int: ... - def __contains__(self, x: object) -> bool: ... - @overload - def __getitem__(self, x: int) -> _T_co: ... - @overload - def __getitem__(self, x: slice) -> Tuple[_T_co, ...]: ... - def __iter__(self) -> Iterator[_T_co]: ... - def __lt__(self, x: Tuple[_T_co, ...]) -> bool: ... - def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... - def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... - def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... - def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... - def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... - def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... - def count(self, x: Any) -> int: ... - if sys.version_info >= (3, 5): - def index(self, x: Any, start: int = ..., end: int = ...) -> int: ... - else: - def index(self, x: Any) -> int: ... - -class function: - # TODO not defined in builtins! - __name__ = ... # type: str - __module__ = ... # type: str - if sys.version_info >= (3,): - __qualname__ = ... # type: str - __code__ = ... # type: CodeType - __annotations__ = ... # type: Dict[str, Any] - -class list(MutableSequence[_T], Generic[_T]): - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, iterable: Iterable[_T]) -> None: ... - if sys.version_info >= (3,): - def clear(self) -> None: ... - def copy(self) -> List[_T]: ... - def append(self, object: _T) -> None: ... - def extend(self, iterable: Iterable[_T]) -> None: ... - def pop(self, index: int = ...) -> _T: ... - def index(self, object: _T, start: int = ..., stop: int = ...) -> int: ... - def count(self, object: _T) -> int: ... - def insert(self, index: int, object: _T) -> None: ... - def remove(self, object: _T) -> None: ... - def reverse(self) -> None: ... - if sys.version_info >= (3,): - def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ... - else: - def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... - - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[_T]: ... - def __str__(self) -> str: ... - def __hash__(self) -> int: ... - @overload - def __getitem__(self, i: int) -> _T: ... - @overload - def __getitem__(self, s: slice) -> List[_T]: ... - @overload - def __setitem__(self, i: int, o: _T) -> None: ... - @overload - def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... - def __delitem__(self, i: Union[int, slice]) -> None: ... - if sys.version_info < (3,): - def __getslice__(self, start: int, stop: int) -> List[_T]: ... - def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... - def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, x: List[_T]) -> List[_T]: ... - def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... - def __mul__(self, n: int) -> List[_T]: ... - def __rmul__(self, n: int) -> List[_T]: ... - if sys.version_info >= (3,): - def __imul__(self, n: int) -> List[_T]: ... - def __contains__(self, o: object) -> bool: ... - def __reversed__(self) -> Iterator[_T]: ... - def __gt__(self, x: List[_T]) -> bool: ... - def __ge__(self, x: List[_T]) -> bool: ... - def __lt__(self, x: List[_T]) -> bool: ... - def __le__(self, x: List[_T]) -> bool: ... - -class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): - # NOTE: Keyword arguments are special. If they are used, _KT must include - # str, but we have no way of enforcing it here. - @overload - def __init__(self, **kwargs: _VT) -> None: ... - @overload - def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... - @overload - def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... - - def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... - - if sys.version_info < (3,): - def has_key(self, k: _KT) -> bool: ... - def clear(self) -> None: ... - def copy(self) -> Dict[_KT, _VT]: ... - def popitem(self) -> Tuple[_KT, _VT]: ... - def setdefault(self, k: _KT, default: Optional[_VT] = ...) -> _VT: ... - @overload - def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... - @overload - def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... - @overload - def update(self, **kwargs: _VT) -> None: ... - if sys.version_info >= (3,): - def keys(self) -> KeysView[_KT]: ... - def values(self) -> ValuesView[_VT]: ... - def items(self) -> ItemsView[_KT, _VT]: ... - else: - def iterkeys(self) -> Iterator[_KT]: ... - def itervalues(self) -> Iterator[_VT]: ... - def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... - def viewkeys(self) -> KeysView[_KT]: ... - def viewvalues(self) -> ValuesView[_VT]: ... - def viewitems(self) -> ItemsView[_KT, _VT]: ... - @staticmethod - @overload - def fromkeys(seq: Iterable[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) - @staticmethod - @overload - def fromkeys(seq: Iterable[_T], value: _S) -> Dict[_T, _S]: ... - def __len__(self) -> int: ... - def __getitem__(self, k: _KT) -> _VT: ... - def __setitem__(self, k: _KT, v: _VT) -> None: ... - def __delitem__(self, v: _KT) -> None: ... - def __iter__(self) -> Iterator[_KT]: ... - def __str__(self) -> str: ... - -class set(MutableSet[_T], Generic[_T]): - def __init__(self, iterable: Iterable[_T] = ...) -> None: ... - def add(self, element: _T) -> None: ... - def clear(self) -> None: ... - def copy(self) -> Set[_T]: ... - def difference(self, *s: Iterable[Any]) -> Set[_T]: ... - def difference_update(self, *s: Iterable[Any]) -> None: ... - def discard(self, element: _T) -> None: ... - def intersection(self, *s: Iterable[Any]) -> Set[_T]: ... - def intersection_update(self, *s: Iterable[Any]) -> None: ... - def isdisjoint(self, s: Iterable[Any]) -> bool: ... - def issubset(self, s: Iterable[Any]) -> bool: ... - def issuperset(self, s: Iterable[Any]) -> bool: ... - def pop(self) -> _T: ... - def remove(self, element: _T) -> None: ... - def symmetric_difference(self, s: Iterable[_T]) -> Set[_T]: ... - def symmetric_difference_update(self, s: Iterable[_T]) -> None: ... - def union(self, *s: Iterable[_T]) -> Set[_T]: ... - def update(self, *s: Iterable[_T]) -> None: ... - def __len__(self) -> int: ... - def __contains__(self, o: object) -> bool: ... - def __iter__(self) -> Iterator[_T]: ... - def __str__(self) -> str: ... - def __and__(self, s: AbstractSet[object]) -> Set[_T]: ... - def __iand__(self, s: AbstractSet[object]) -> Set[_T]: ... - def __or__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... - def __ior__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... - def __sub__(self, s: AbstractSet[object]) -> Set[_T]: ... - def __isub__(self, s: AbstractSet[object]) -> Set[_T]: ... - def __xor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... - def __ixor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... - def __le__(self, s: AbstractSet[object]) -> bool: ... - def __lt__(self, s: AbstractSet[object]) -> bool: ... - def __ge__(self, s: AbstractSet[object]) -> bool: ... - def __gt__(self, s: AbstractSet[object]) -> bool: ... - -class frozenset(AbstractSet[_T], Generic[_T]): - def __init__(self, iterable: Iterable[_T] = ...) -> None: ... - def copy(self) -> FrozenSet[_T]: ... - def difference(self, *s: Iterable[object]) -> FrozenSet[_T]: ... - def intersection(self, *s: Iterable[object]) -> FrozenSet[_T]: ... - def isdisjoint(self, s: Iterable[_T]) -> bool: ... - def issubset(self, s: Iterable[object]) -> bool: ... - def issuperset(self, s: Iterable[object]) -> bool: ... - def symmetric_difference(self, s: Iterable[_T]) -> FrozenSet[_T]: ... - def union(self, *s: Iterable[_T]) -> FrozenSet[_T]: ... - def __len__(self) -> int: ... - def __contains__(self, o: object) -> bool: ... - def __iter__(self) -> Iterator[_T]: ... - def __str__(self) -> str: ... - def __and__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... - def __or__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... - def __sub__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... - def __xor__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... - def __le__(self, s: AbstractSet[object]) -> bool: ... - def __lt__(self, s: AbstractSet[object]) -> bool: ... - def __ge__(self, s: AbstractSet[object]) -> bool: ... - def __gt__(self, s: AbstractSet[object]) -> bool: ... - -class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): - def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... - def __iter__(self) -> Iterator[Tuple[int, _T]]: ... - if sys.version_info >= (3,): - def __next__(self) -> Tuple[int, _T]: ... - else: - def next(self) -> Tuple[int, _T]: ... - # TODO __getattribute__ - -if sys.version_info >= (3,): - class range(Sequence[int]): - start = ... # type: int - stop = ... # type: int - step = ... # type: int - @overload - def __init__(self, stop: int) -> None: ... - @overload - def __init__(self, start: int, stop: int, step: int = ...) -> None: ... - def count(self, value: int) -> int: ... - def index(self, value: int, start: int = ..., stop: Optional[int] = ...) -> int: ... - def __len__(self) -> int: ... - def __contains__(self, o: object) -> bool: ... - def __iter__(self) -> Iterator[int]: ... - @overload - def __getitem__(self, i: int) -> int: ... - @overload - def __getitem__(self, s: slice) -> range: ... - def __repr__(self) -> str: ... - def __reversed__(self) -> Iterator[int]: ... -else: - class xrange(Sized, Iterable[int], Reversible[int]): - @overload - def __init__(self, stop: int) -> None: ... - @overload - def __init__(self, start: int, stop: int, step: int = ...) -> None: ... - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[int]: ... - def __getitem__(self, i: int) -> int: ... - def __reversed__(self) -> Iterator[int]: ... - -class property(object): - def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., - fset: Optional[Callable[[Any, Any], None]] = ..., - fdel: Optional[Callable[[Any], None]] = ..., - doc: Optional[str] = ...) -> None: ... - def getter(self, fget: Callable[[Any], Any]) -> property: ... - def setter(self, fset: Callable[[Any, Any], None]) -> property: ... - def deleter(self, fdel: Callable[[Any], None]) -> property: ... - def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ... - def __set__(self, obj: Any, value: Any) -> None: ... - def __delete__(self, obj: Any) -> None: ... - def fget(self) -> Any: ... - def fset(self, value: Any) -> None: ... - def fdel(self) -> None: ... - -if sys.version_info < (3,): - long = int - -NotImplemented = ... # type: Any - -def abs(n: SupportsAbs[_T]) -> _T: ... -def all(i: Iterable[object]) -> bool: ... -def any(i: Iterable[object]) -> bool: ... -if sys.version_info < (3,): - def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... -if sys.version_info >= (3,): - def ascii(o: object) -> str: ... -def bin(number: int) -> str: ... -if sys.version_info >= (3, 7): - def breakpoint(*args: Any, **kws: Any) -> None: ... -def callable(o: object) -> bool: ... -def chr(code: int) -> str: ... -if sys.version_info < (3,): - def cmp(x: Any, y: Any) -> int: ... - _N1 = TypeVar('_N1', bool, int, float, complex) - def coerce(x: _N1, y: _N1) -> Tuple[_N1, _N1]: ... -if sys.version_info >= (3, 6): - # This class is to be exported as PathLike from os, - # but we define it here as _PathLike to avoid import cycle issues. - # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 - class _PathLike(Generic[AnyStr]): - def __fspath__(self) -> AnyStr: ... - def compile(source: Any, filename: Union[str, bytes, _PathLike], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... -else: - def compile(source: Any, filename: Union[str, bytes], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... -if sys.version_info >= (3,): - def copyright() -> None: ... - def credits() -> None: ... -def delattr(o: Any, name: Text) -> None: ... -def dir(o: object = ...) -> List[str]: ... -_N2 = TypeVar('_N2', int, float) -def divmod(a: _N2, b: _N2) -> Tuple[_N2, _N2]: ... -def eval(source: Union[Text, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... -if sys.version_info >= (3,): - def exec(object: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... -else: - def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... -def exit(code: Any = ...) -> NoReturn: ... -if sys.version_info >= (3,): - @overload - def filter(__function: None, __iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... - @overload - def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Iterator[_T]: ... -else: - @overload - def filter(__function: Callable[[AnyStr], Any], # type: ignore - __iterable: AnyStr) -> AnyStr: ... - @overload - def filter(__function: None, # type: ignore - __iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ... - @overload - def filter(__function: Callable[[_T], Any], # type: ignore - __iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ... - @overload - def filter(__function: None, - __iterable: Iterable[Optional[_T]]) -> List[_T]: ... - @overload - def filter(__function: Callable[[_T], Any], - __iterable: Iterable[_T]) -> List[_T]: ... -def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode -def getattr(o: Any, name: Text, default: Any = ...) -> Any: ... -def globals() -> Dict[str, Any]: ... -def hasattr(o: Any, name: Text) -> bool: ... -def hash(o: object) -> int: ... -if sys.version_info >= (3,): - def help(*args: Any, **kwds: Any) -> None: ... -def hex(i: int) -> str: ... # TODO __index__ -def id(o: object) -> int: ... -if sys.version_info >= (3,): - def input(prompt: Any = ...) -> str: ... -else: - def input(prompt: Any = ...) -> Any: ... - def intern(string: str) -> str: ... -@overload -def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... -@overload -def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ... -def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... -def issubclass(cls: type, classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... -def len(o: Sized) -> int: ... -if sys.version_info >= (3,): - def license() -> None: ... -def locals() -> Dict[str, Any]: ... -if sys.version_info >= (3,): - @overload - def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... - @overload - def map(func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> Iterator[_S]: ... - @overload - def map(func: Callable[[_T1, _T2, _T3], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> Iterator[_S]: ... - @overload - def map(func: Callable[[_T1, _T2, _T3, _T4], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> Iterator[_S]: ... - @overload - def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> Iterator[_S]: ... - @overload - def map(func: Callable[..., _S], - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> Iterator[_S]: ... -else: - @overload - def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... - @overload - def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... - @overload - def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... - @overload - def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... - @overload - def map(func: None, - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... - @overload - def map(func: None, - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... - @overload - def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... - @overload - def map(func: Callable[[_T1, _T2], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[_S]: ... - @overload - def map(func: Callable[[_T1, _T2, _T3], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[_S]: ... - @overload - def map(func: Callable[[_T1, _T2, _T3, _T4], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[_S]: ... - @overload - def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], - iter1: Iterable[_T1], - iter2: Iterable[_T2], - iter3: Iterable[_T3], - iter4: Iterable[_T4], - iter5: Iterable[_T5]) -> List[_S]: ... - @overload - def map(func: Callable[..., _S], - iter1: Iterable[Any], - iter2: Iterable[Any], - iter3: Iterable[Any], - iter4: Iterable[Any], - iter5: Iterable[Any], - iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[_S]: ... -if sys.version_info >= (3,): - @overload - def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... - @overload - def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... -else: - @overload - def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... - @overload - def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... -if sys.version_info >= (3,): - @overload - def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... - @overload - def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... -else: - @overload - def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... - @overload - def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... -@overload -def next(i: Iterator[_T]) -> _T: ... -@overload -def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... -def oct(i: int) -> str: ... # TODO __index__ - -if sys.version_info >= (3, 6): - def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., - errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... -elif sys.version_info >= (3,): - def open(file: Union[str, bytes, int], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., - errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... -else: - def open(file: Union[unicode, int], mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... - -def ord(c: Union[str, bytes]) -> int: ... -if sys.version_info >= (3,): - def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[str]] = ..., flush: bool = ...) -> None: ... -else: - # This is only available after from __future__ import print_function. - def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[Any]] = ...) -> None: ... -@overload -def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y -@overload -def pow(x: int, y: int, z: int) -> Any: ... -@overload -def pow(x: float, y: float) -> float: ... -@overload -def pow(x: float, y: float, z: float) -> float: ... -def quit(code: Optional[int] = ...) -> None: ... -if sys.version_info < (3,): - def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... - def raw_input(prompt: Any = ...) -> str: ... - @overload - def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... - @overload - def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... - def reload(module: Any) -> Any: ... -@overload -def reversed(object: Sequence[_T]) -> Iterator[_T]: ... -@overload -def reversed(object: Reversible[_T]) -> Iterator[_T]: ... -def repr(o: object) -> str: ... -if sys.version_info >= (3,): - @overload - def round(number: float) -> int: ... - @overload - def round(number: float, ndigits: None) -> int: ... - @overload - def round(number: float, ndigits: int) -> float: ... - @overload - def round(number: SupportsRound[_T]) -> int: ... - @overload - def round(number: SupportsRound[_T], ndigits: None) -> int: ... # type: ignore - @overload - def round(number: SupportsRound[_T], ndigits: int) -> _T: ... -else: - @overload - def round(number: float) -> float: ... - @overload - def round(number: float, ndigits: int) -> float: ... - @overload - def round(number: SupportsRound[_T]) -> _T: ... - @overload - def round(number: SupportsRound[_T], ndigits: int) -> _T: ... -def setattr(object: Any, name: Text, value: Any) -> None: ... -if sys.version_info >= (3,): - def sorted(iterable: Iterable[_T], *, - key: Optional[Callable[[_T], Any]] = ..., - reverse: bool = ...) -> List[_T]: ... -else: - def sorted(iterable: Iterable[_T], *, - cmp: Callable[[_T, _T], int] = ..., - key: Callable[[_T], Any] = ..., - reverse: bool = ...) -> List[_T]: ... -@overload -def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... -@overload -def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... -if sys.version_info < (3,): - def unichr(i: int) -> unicode: ... -def vars(object: Any = ...) -> Dict[str, Any]: ... -if sys.version_info >= (3,): - @overload - def zip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... - @overload - def zip(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... - @overload - def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... - @overload - def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, - _T3, _T4]]: ... - @overload - def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4], iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, - _T3, _T4, _T5]]: ... - @overload - def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], - iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], - *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... -else: - @overload - def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... - @overload - def zip(iter1: Iterable[_T1], - iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... - @overload - def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], - iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... - @overload - def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, - _T3, _T4]]: ... - @overload - def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, - _T3, _T4, _T5]]: ... - @overload - def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], - iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], - *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., - fromlist: List[str] = ..., level: int = ...) -> Any: ... - -# Actually the type of Ellipsis is , but since it's -# not exposed anywhere under that name, we make it private here. -class ellipsis: ... -Ellipsis = ... # type: ellipsis - -if sys.version_info < (3,): - # TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. - _AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) - - class buffer(Sized): - def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... - def __add__(self, other: _AnyBuffer) -> str: ... - def __cmp__(self, other: _AnyBuffer) -> bool: ... - def __getitem__(self, key: Union[int, slice]) -> str: ... - def __getslice__(self, i: int, j: int) -> str: ... - def __len__(self) -> int: ... - def __mul__(self, x: int) -> str: ... - -class BaseException(object): - args = ... # type: Tuple[Any, ...] - if sys.version_info < (3,): - message = ... # type: Any - if sys.version_info >= (3,): - __cause__ = ... # type: Optional[BaseException] - __context__ = ... # type: Optional[BaseException] - __traceback__ = ... # type: Optional[TracebackType] - def __init__(self, *args: object) -> None: ... - if sys.version_info < (3,): - def __getitem__(self, i: int) -> Any: ... - def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... - if sys.version_info >= (3,): - def with_traceback(self, tb: Optional[TracebackType]) -> BaseException: ... - -class GeneratorExit(BaseException): ... -class KeyboardInterrupt(BaseException): ... -class SystemExit(BaseException): - code = 0 -class Exception(BaseException): ... -class StopIteration(Exception): ... -if sys.version_info >= (3,): - _StandardError = Exception - class OSError(Exception): - errno = 0 - strerror = ... # type: str - # filename, filename2 are actually Union[str, bytes, None] - filename = ... # type: Any - filename2 = ... # type: Any - EnvironmentError = OSError - IOError = OSError -else: - class StandardError(Exception): ... - _StandardError = StandardError - class EnvironmentError(StandardError): - errno = 0 - strerror = ... # type: str - # TODO can this be unicode? - filename = ... # type: str - class OSError(EnvironmentError): ... - class IOError(EnvironmentError): ... - -class ArithmeticError(_StandardError): ... -class AssertionError(_StandardError): ... -class AttributeError(_StandardError): ... -class BufferError(_StandardError): ... -class EOFError(_StandardError): ... -class ImportError(_StandardError): - if sys.version_info >= (3,): - name = ... # type: str - path = ... # type: str -class LookupError(_StandardError): ... -class MemoryError(_StandardError): ... -class NameError(_StandardError): ... -class ReferenceError(_StandardError): ... -class RuntimeError(_StandardError): ... -if sys.version_info >= (3, 5): - class StopAsyncIteration(Exception): - value = ... # type: Any -class SyntaxError(_StandardError): - msg = ... # type: str - lineno = ... # type: int - offset = ... # type: int - text = ... # type: str - filename = ... # type: str -class SystemError(_StandardError): ... -class TypeError(_StandardError): ... -class ValueError(_StandardError): ... - -class FloatingPointError(ArithmeticError): ... -class OverflowError(ArithmeticError): ... -class ZeroDivisionError(ArithmeticError): ... - -if sys.version_info >= (3, 6): - class ModuleNotFoundError(ImportError): ... - -class IndexError(LookupError): ... -class KeyError(LookupError): ... - -class UnboundLocalError(NameError): ... - -class WindowsError(OSError): - winerror = ... # type: int -if sys.version_info >= (3,): - class BlockingIOError(OSError): - characters_written = 0 - class ChildProcessError(OSError): ... - class ConnectionError(OSError): ... - class BrokenPipeError(ConnectionError): ... - class ConnectionAbortedError(ConnectionError): ... - class ConnectionRefusedError(ConnectionError): ... - class ConnectionResetError(ConnectionError): ... - class FileExistsError(OSError): ... - class FileNotFoundError(OSError): ... - class InterruptedError(OSError): ... - class IsADirectoryError(OSError): ... - class NotADirectoryError(OSError): ... - class PermissionError(OSError): ... - class ProcessLookupError(OSError): ... - class TimeoutError(OSError): ... - -class NotImplementedError(RuntimeError): ... -if sys.version_info >= (3, 5): - class RecursionError(RuntimeError): ... - -class IndentationError(SyntaxError): ... -class TabError(IndentationError): ... - -class UnicodeError(ValueError): ... -class UnicodeDecodeError(UnicodeError): - encoding: str - object: bytes - start: int - end: int - reason: str - def __init__(self, __encoding: str, __object: bytes, __start: int, __end: int, - __reason: str) -> None: ... -class UnicodeEncodeError(UnicodeError): - encoding: str - object: Text - start: int - end: int - reason: str - def __init__(self, __encoding: str, __object: Text, __start: int, __end: int, - __reason: str) -> None: ... -class UnicodeTranslateError(UnicodeError): ... - -class Warning(Exception): ... -class UserWarning(Warning): ... -class DeprecationWarning(Warning): ... -class SyntaxWarning(Warning): ... -class RuntimeWarning(Warning): ... -class FutureWarning(Warning): ... -class PendingDeprecationWarning(Warning): ... -class ImportWarning(Warning): ... -class UnicodeWarning(Warning): ... -class BytesWarning(Warning): ... -if sys.version_info >= (3, 2): - class ResourceWarning(Warning): ... - -if sys.version_info < (3,): - class file(BinaryIO): - @overload - def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... - @overload - def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... - @overload - def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... - def __iter__(self) -> Iterator[str]: ... - def next(self) -> str: ... - def read(self, n: int = ...) -> str: ... - def __enter__(self) -> BinaryIO: ... - def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... - def flush(self) -> None: ... - def fileno(self) -> int: ... - def isatty(self) -> bool: ... - def close(self) -> None: ... - - def readable(self) -> bool: ... - def writable(self) -> bool: ... - def seekable(self) -> bool: ... - def seek(self, offset: int, whence: int = ...) -> int: ... - def tell(self) -> int: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... - def write(self, data: str) -> int: ... - def writelines(self, data: Iterable[str]) -> None: ... - def truncate(self, pos: Optional[int] = ...) -> int: ... diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 08e9bd5a1131..f7f70a9c5ee9 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -7,7 +7,7 @@ import filecmp consistent_files = [ - {'stdlib/2/builtins.pyi', 'stdlib/2/__builtin__.pyi'}, + {'stdlib/2and3/builtins.pyi', 'stdlib/2/__builtin__.pyi'}, {'stdlib/2/SocketServer.pyi', 'stdlib/3/socketserver.pyi'}, {'stdlib/2/os2emxpath.pyi', 'stdlib/2/posixpath.pyi', 'stdlib/2/ntpath.pyi', 'stdlib/2/macpath.pyi'}, {'stdlib/2and3/pyexpat/__init__.pyi', 'stdlib/2and3/xml/parsers/expat/__init__.pyi'}, From 1322415d7f2a563a54f2c79705f0619fc6772292 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 21 Oct 2018 21:06:36 +0200 Subject: [PATCH 3/9] Use variable annotations --- stdlib/2/__builtin__.pyi | 118 +++++++++++++++++++------------------- stdlib/2and3/builtins.pyi | 118 +++++++++++++++++++------------------- 2 files changed, 118 insertions(+), 118 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index cda0a31616b3..e952b6d9fbcd 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -28,12 +28,12 @@ _T5 = TypeVar('_T5') _TT = TypeVar('_TT', bound='type') class object: - __doc__ = ... # type: Optional[str] - __dict__ = ... # type: Dict[str, Any] - __slots__ = ... # type: Union[Text, Iterable[Text]] - __module__ = ... # type: str + __doc__: Optional[str] + __dict__: Dict[str, Any] + __slots__: Union[Text, Iterable[Text]] + __module__: str if sys.version_info >= (3, 6): - __annotations__ = ... # type: Dict[str, Any] + __annotations__: Dict[str, Any] @property def __class__(self: _T) -> Type[_T]: ... @@ -59,31 +59,31 @@ class object: def __init_subclass__(cls) -> None: ... class staticmethod(object): # Special, only valid as a decorator. - __func__ = ... # type: function + __func__: function if sys.version_info >= (3,): - __isabstractmethod__ = ... # type: bool + __isabstractmethod__: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... class classmethod(object): # Special, only valid as a decorator. - __func__ = ... # type: function + __func__: function if sys.version_info >= (3,): - __isabstractmethod__ = ... # type: bool + __isabstractmethod__: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... class type(object): - __bases__ = ... # type: Tuple[type, ...] - __name__ = ... # type: str - __module__ = ... # type: str + __bases__: Tuple[type, ...] + __name__: str + __module__: str if sys.version_info >= (3,): - __qualname__ = ... # type: str - __dict__ = ... # type: Dict[str, Any] - __mro__ = ... # type: Tuple[type, ...] + __qualname__: str + __dict__: Dict[str, Any] + __mro__: Tuple[type, ...] @overload def __init__(self, o: object) -> None: ... @@ -97,7 +97,7 @@ class type(object): def __subclasses__(self: _TT) -> List[_TT]: ... if sys.version_info < (3,): # Only new-style classes - __mro__ = ... # type: Tuple[type, ...] + __mro__: Tuple[type, ...] # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... @@ -723,13 +723,13 @@ else: _mv_container_type = str class memoryview(Sized, Container[_mv_container_type]): - format = ... # type: str - itemsize = ... # type: int - shape = ... # type: Optional[Tuple[int, ...]] - strides = ... # type: Optional[Tuple[int, ...]] - suboffsets = ... # type: Optional[Tuple[int, ...]] - readonly = ... # type: bool - ndim = ... # type: int + format: str + itemsize: int + shape: Optional[Tuple[int, ...]] + strides: Optional[Tuple[int, ...]] + suboffsets: Optional[Tuple[int, ...]] + readonly: bool + ndim: int if sys.version_info >= (3,): def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... @@ -788,9 +788,9 @@ class bool(int): def __rxor__(self, x: int) -> int: ... class slice(object): - start = ... # type: Optional[int] - step = ... # type: Optional[int] - stop = ... # type: Optional[int] + start: Optional[int] + step: Optional[int] + stop: Optional[int] @overload def __init__(self, stop: Optional[int]) -> None: ... @overload @@ -821,12 +821,12 @@ class tuple(Sequence[_T_co], Generic[_T_co]): class function: # TODO not defined in builtins! - __name__ = ... # type: str - __module__ = ... # type: str + __name__: str + __module__: str if sys.version_info >= (3,): - __qualname__ = ... # type: str - __code__ = ... # type: CodeType - __annotations__ = ... # type: Dict[str, Any] + __qualname__: str + __code__: CodeType + __annotations__: Dict[str, Any] class list(MutableSequence[_T], Generic[_T]): @overload @@ -997,9 +997,9 @@ class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): if sys.version_info >= (3,): class range(Sequence[int]): - start = ... # type: int - stop = ... # type: int - step = ... # type: int + start: int + stop: int + step: int @overload def __init__(self, stop: int) -> None: ... @overload @@ -1044,7 +1044,7 @@ class property(object): if sys.version_info < (3,): long = int -NotImplemented = ... # type: Any +NotImplemented: Any def abs(n: SupportsAbs[_T]) -> _T: ... def all(i: Iterable[object]) -> bool: ... @@ -1378,7 +1378,7 @@ def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. class ellipsis: ... -Ellipsis = ... # type: ellipsis +Ellipsis: ellipsis if sys.version_info < (3,): # TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. @@ -1394,13 +1394,13 @@ if sys.version_info < (3,): def __mul__(self, x: int) -> str: ... class BaseException(object): - args = ... # type: Tuple[Any, ...] + args: Tuple[Any, ...] if sys.version_info < (3,): - message = ... # type: Any + message: Any if sys.version_info >= (3,): - __cause__ = ... # type: Optional[BaseException] - __context__ = ... # type: Optional[BaseException] - __traceback__ = ... # type: Optional[TracebackType] + __cause__: Optional[BaseException] + __context__: Optional[BaseException] + __traceback__: Optional[TracebackType] def __init__(self, *args: object) -> None: ... if sys.version_info < (3,): def __getitem__(self, i: int) -> Any: ... @@ -1411,27 +1411,27 @@ class BaseException(object): class GeneratorExit(BaseException): ... class KeyboardInterrupt(BaseException): ... class SystemExit(BaseException): - code = 0 + code: int class Exception(BaseException): ... class StopIteration(Exception): ... if sys.version_info >= (3,): _StandardError = Exception class OSError(Exception): - errno = 0 - strerror = ... # type: str + errno: int + strerror: str # filename, filename2 are actually Union[str, bytes, None] - filename = ... # type: Any - filename2 = ... # type: Any + filename: Any + filename2: Any EnvironmentError = OSError IOError = OSError else: class StandardError(Exception): ... _StandardError = StandardError class EnvironmentError(StandardError): - errno = 0 - strerror = ... # type: str + errno: int + strerror: str # TODO can this be unicode? - filename = ... # type: str + filename: str class OSError(EnvironmentError): ... class IOError(EnvironmentError): ... @@ -1442,8 +1442,8 @@ class BufferError(_StandardError): ... class EOFError(_StandardError): ... class ImportError(_StandardError): if sys.version_info >= (3,): - name = ... # type: str - path = ... # type: str + name: str + path: str class LookupError(_StandardError): ... class MemoryError(_StandardError): ... class NameError(_StandardError): ... @@ -1451,13 +1451,13 @@ class ReferenceError(_StandardError): ... class RuntimeError(_StandardError): ... if sys.version_info >= (3, 5): class StopAsyncIteration(Exception): - value = ... # type: Any + value: Any class SyntaxError(_StandardError): - msg = ... # type: str - lineno = ... # type: int - offset = ... # type: int - text = ... # type: str - filename = ... # type: str + msg: str + lineno: int + offset: int + text: str + filename: str class SystemError(_StandardError): ... class TypeError(_StandardError): ... class ValueError(_StandardError): ... @@ -1475,10 +1475,10 @@ class KeyError(LookupError): ... class UnboundLocalError(NameError): ... class WindowsError(OSError): - winerror = ... # type: int + winerror: int if sys.version_info >= (3,): class BlockingIOError(OSError): - characters_written = 0 + characters_written: int class ChildProcessError(OSError): ... class ConnectionError(OSError): ... class BrokenPipeError(ConnectionError): ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index cda0a31616b3..e952b6d9fbcd 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -28,12 +28,12 @@ _T5 = TypeVar('_T5') _TT = TypeVar('_TT', bound='type') class object: - __doc__ = ... # type: Optional[str] - __dict__ = ... # type: Dict[str, Any] - __slots__ = ... # type: Union[Text, Iterable[Text]] - __module__ = ... # type: str + __doc__: Optional[str] + __dict__: Dict[str, Any] + __slots__: Union[Text, Iterable[Text]] + __module__: str if sys.version_info >= (3, 6): - __annotations__ = ... # type: Dict[str, Any] + __annotations__: Dict[str, Any] @property def __class__(self: _T) -> Type[_T]: ... @@ -59,31 +59,31 @@ class object: def __init_subclass__(cls) -> None: ... class staticmethod(object): # Special, only valid as a decorator. - __func__ = ... # type: function + __func__: function if sys.version_info >= (3,): - __isabstractmethod__ = ... # type: bool + __isabstractmethod__: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... class classmethod(object): # Special, only valid as a decorator. - __func__ = ... # type: function + __func__: function if sys.version_info >= (3,): - __isabstractmethod__ = ... # type: bool + __isabstractmethod__: bool def __init__(self, f: function) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... class type(object): - __bases__ = ... # type: Tuple[type, ...] - __name__ = ... # type: str - __module__ = ... # type: str + __bases__: Tuple[type, ...] + __name__: str + __module__: str if sys.version_info >= (3,): - __qualname__ = ... # type: str - __dict__ = ... # type: Dict[str, Any] - __mro__ = ... # type: Tuple[type, ...] + __qualname__: str + __dict__: Dict[str, Any] + __mro__: Tuple[type, ...] @overload def __init__(self, o: object) -> None: ... @@ -97,7 +97,7 @@ class type(object): def __subclasses__(self: _TT) -> List[_TT]: ... if sys.version_info < (3,): # Only new-style classes - __mro__ = ... # type: Tuple[type, ...] + __mro__: Tuple[type, ...] # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... @@ -723,13 +723,13 @@ else: _mv_container_type = str class memoryview(Sized, Container[_mv_container_type]): - format = ... # type: str - itemsize = ... # type: int - shape = ... # type: Optional[Tuple[int, ...]] - strides = ... # type: Optional[Tuple[int, ...]] - suboffsets = ... # type: Optional[Tuple[int, ...]] - readonly = ... # type: bool - ndim = ... # type: int + format: str + itemsize: int + shape: Optional[Tuple[int, ...]] + strides: Optional[Tuple[int, ...]] + suboffsets: Optional[Tuple[int, ...]] + readonly: bool + ndim: int if sys.version_info >= (3,): def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... @@ -788,9 +788,9 @@ class bool(int): def __rxor__(self, x: int) -> int: ... class slice(object): - start = ... # type: Optional[int] - step = ... # type: Optional[int] - stop = ... # type: Optional[int] + start: Optional[int] + step: Optional[int] + stop: Optional[int] @overload def __init__(self, stop: Optional[int]) -> None: ... @overload @@ -821,12 +821,12 @@ class tuple(Sequence[_T_co], Generic[_T_co]): class function: # TODO not defined in builtins! - __name__ = ... # type: str - __module__ = ... # type: str + __name__: str + __module__: str if sys.version_info >= (3,): - __qualname__ = ... # type: str - __code__ = ... # type: CodeType - __annotations__ = ... # type: Dict[str, Any] + __qualname__: str + __code__: CodeType + __annotations__: Dict[str, Any] class list(MutableSequence[_T], Generic[_T]): @overload @@ -997,9 +997,9 @@ class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): if sys.version_info >= (3,): class range(Sequence[int]): - start = ... # type: int - stop = ... # type: int - step = ... # type: int + start: int + stop: int + step: int @overload def __init__(self, stop: int) -> None: ... @overload @@ -1044,7 +1044,7 @@ class property(object): if sys.version_info < (3,): long = int -NotImplemented = ... # type: Any +NotImplemented: Any def abs(n: SupportsAbs[_T]) -> _T: ... def all(i: Iterable[object]) -> bool: ... @@ -1378,7 +1378,7 @@ def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. class ellipsis: ... -Ellipsis = ... # type: ellipsis +Ellipsis: ellipsis if sys.version_info < (3,): # TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. @@ -1394,13 +1394,13 @@ if sys.version_info < (3,): def __mul__(self, x: int) -> str: ... class BaseException(object): - args = ... # type: Tuple[Any, ...] + args: Tuple[Any, ...] if sys.version_info < (3,): - message = ... # type: Any + message: Any if sys.version_info >= (3,): - __cause__ = ... # type: Optional[BaseException] - __context__ = ... # type: Optional[BaseException] - __traceback__ = ... # type: Optional[TracebackType] + __cause__: Optional[BaseException] + __context__: Optional[BaseException] + __traceback__: Optional[TracebackType] def __init__(self, *args: object) -> None: ... if sys.version_info < (3,): def __getitem__(self, i: int) -> Any: ... @@ -1411,27 +1411,27 @@ class BaseException(object): class GeneratorExit(BaseException): ... class KeyboardInterrupt(BaseException): ... class SystemExit(BaseException): - code = 0 + code: int class Exception(BaseException): ... class StopIteration(Exception): ... if sys.version_info >= (3,): _StandardError = Exception class OSError(Exception): - errno = 0 - strerror = ... # type: str + errno: int + strerror: str # filename, filename2 are actually Union[str, bytes, None] - filename = ... # type: Any - filename2 = ... # type: Any + filename: Any + filename2: Any EnvironmentError = OSError IOError = OSError else: class StandardError(Exception): ... _StandardError = StandardError class EnvironmentError(StandardError): - errno = 0 - strerror = ... # type: str + errno: int + strerror: str # TODO can this be unicode? - filename = ... # type: str + filename: str class OSError(EnvironmentError): ... class IOError(EnvironmentError): ... @@ -1442,8 +1442,8 @@ class BufferError(_StandardError): ... class EOFError(_StandardError): ... class ImportError(_StandardError): if sys.version_info >= (3,): - name = ... # type: str - path = ... # type: str + name: str + path: str class LookupError(_StandardError): ... class MemoryError(_StandardError): ... class NameError(_StandardError): ... @@ -1451,13 +1451,13 @@ class ReferenceError(_StandardError): ... class RuntimeError(_StandardError): ... if sys.version_info >= (3, 5): class StopAsyncIteration(Exception): - value = ... # type: Any + value: Any class SyntaxError(_StandardError): - msg = ... # type: str - lineno = ... # type: int - offset = ... # type: int - text = ... # type: str - filename = ... # type: str + msg: str + lineno: int + offset: int + text: str + filename: str class SystemError(_StandardError): ... class TypeError(_StandardError): ... class ValueError(_StandardError): ... @@ -1475,10 +1475,10 @@ class KeyError(LookupError): ... class UnboundLocalError(NameError): ... class WindowsError(OSError): - winerror = ... # type: int + winerror: int if sys.version_info >= (3,): class BlockingIOError(OSError): - characters_written = 0 + characters_written: int class ChildProcessError(OSError): ... class ConnectionError(OSError): ... class BrokenPipeError(ConnectionError): ... From de79fa8b44af2afc3913d15b795cb25d95accb1c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 21 Oct 2018 22:41:44 +0200 Subject: [PATCH 4/9] Update pytype blacklist --- tests/pytype_blacklist.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/pytype_blacklist.txt b/tests/pytype_blacklist.txt index b9d6511b3cd1..306b62bd0334 100644 --- a/tests/pytype_blacklist.txt +++ b/tests/pytype_blacklist.txt @@ -3,9 +3,8 @@ # pytype has its own version of these files, and thus doesn't mind if it # can't parse the typeshed version: stdlib/2/__builtin__.pyi -stdlib/2/builtins.pyi stdlib/2/typing.pyi -stdlib/3/builtins.pyi +stdlib/2and3/builtins.pyi stdlib/3/typing.pyi stdlib/3/collections/__init__.pyi # parse only From 0bc70f6279e31b1b6548804e54a3d8d0e14cc6ad Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 27 Oct 2018 12:32:47 +0200 Subject: [PATCH 5/9] Small fixes per @JelleZijlstra --- stdlib/2and3/builtins.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index fcd1f56287fe..a225b6eb19ee 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -83,7 +83,7 @@ class type(object): if sys.version_info >= (3,): __qualname__: str __dict__: Dict[str, Any] - __mro__: Tuple[type, ...] + __mro__: Tuple[type, ...] @overload def __init__(self, o: object) -> None: ... @@ -912,7 +912,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... def popitem(self) -> Tuple[_KT, _VT]: ... - def setdefault(self, k: _KT, default: Optional[_VT] = ...) -> _VT: ... + def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... @overload def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... @overload @@ -1009,7 +1009,6 @@ class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): def __next__(self) -> Tuple[int, _T]: ... else: def next(self) -> Tuple[int, _T]: ... - # TODO __getattribute__ if sys.version_info >= (3,): class range(Sequence[int]): From 1403f56bd6476e4c1e37df9673246357ab19ddc4 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 31 Oct 2018 08:39:52 +0100 Subject: [PATCH 6/9] Copy 2and3/builtins.pyi to 2/__builtins__.pyi --- stdlib/2/__builtin__.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index fcd1f56287fe..a225b6eb19ee 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -83,7 +83,7 @@ class type(object): if sys.version_info >= (3,): __qualname__: str __dict__: Dict[str, Any] - __mro__: Tuple[type, ...] + __mro__: Tuple[type, ...] @overload def __init__(self, o: object) -> None: ... @@ -912,7 +912,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... def popitem(self) -> Tuple[_KT, _VT]: ... - def setdefault(self, k: _KT, default: Optional[_VT] = ...) -> _VT: ... + def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... @overload def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... @overload @@ -1009,7 +1009,6 @@ class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): def __next__(self) -> Tuple[int, _T]: ... else: def next(self) -> Tuple[int, _T]: ... - # TODO __getattribute__ if sys.version_info >= (3,): class range(Sequence[int]): From 41a81040502bd4f52c25b470130373c87ae95ef1 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 31 Oct 2018 09:03:50 +0100 Subject: [PATCH 7/9] Remove duplicate definition of __mro__ --- stdlib/2/__builtin__.pyi | 5 +---- stdlib/2and3/builtins.pyi | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index a225b6eb19ee..ea7b0d369892 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -83,7 +83,7 @@ class type(object): if sys.version_info >= (3,): __qualname__: str __dict__: Dict[str, Any] - __mro__: Tuple[type, ...] + __mro__: Tuple[type, ...] # Only new-style classes @overload def __init__(self, o: object) -> None: ... @@ -95,9 +95,6 @@ class type(object): def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... def __subclasses__(self: _TT) -> List[_TT]: ... - if sys.version_info < (3,): - # Only new-style classes - __mro__: Tuple[type, ...] # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index a225b6eb19ee..ea7b0d369892 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -83,7 +83,7 @@ class type(object): if sys.version_info >= (3,): __qualname__: str __dict__: Dict[str, Any] - __mro__: Tuple[type, ...] + __mro__: Tuple[type, ...] # Only new-style classes @overload def __init__(self, o: object) -> None: ... @@ -95,9 +95,6 @@ class type(object): def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... def __subclasses__(self: _TT) -> List[_TT]: ... - if sys.version_info < (3,): - # Only new-style classes - __mro__: Tuple[type, ...] # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... From 99d7f86d624180723075577fc651f3d6c59770e1 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 23 Nov 2018 08:54:57 +0100 Subject: [PATCH 8/9] Remove unneeded ignores --- stdlib/2and3/builtins.pyi | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index a5ca91d407ac..0234fefcb415 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -776,29 +776,29 @@ class memoryview(Sized, Container[_mv_container_type]): class bool(int): def __init__(self, o: object = ...) -> None: ... - @overload # type: ignore + @overload def __and__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __and__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __or__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __or__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __xor__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __xor__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __rand__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __rand__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __ror__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __ror__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __rxor__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __rxor__(self, x: int) -> int: ... class slice(object): From 7a3c5263fa576213f5894911d98dd4716c6ccbce Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 23 Nov 2018 09:30:45 +0100 Subject: [PATCH 9/9] Copy builtins file --- stdlib/2/__builtin__.pyi | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index a5ca91d407ac..0234fefcb415 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -776,29 +776,29 @@ class memoryview(Sized, Container[_mv_container_type]): class bool(int): def __init__(self, o: object = ...) -> None: ... - @overload # type: ignore + @overload def __and__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __and__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __or__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __or__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __xor__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __xor__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __rand__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __rand__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __ror__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __ror__(self, x: int) -> int: ... - @overload # type: ignore + @overload def __rxor__(self, x: bool) -> bool: ... - @overload # type: ignore + @overload def __rxor__(self, x: int) -> int: ... class slice(object):