diff --git a/stdlib/2.7/__builtin__.pyi b/stdlib/2.7/__builtin__.pyi index 9e3dd333205a..c00464757ab8 100644 --- a/stdlib/2.7/__builtin__.pyi +++ b/stdlib/2.7/__builtin__.pyi @@ -114,6 +114,8 @@ class int(SupportsInt, SupportsFloat, SupportsAbs[int]): def __abs__(self) -> int: ... def __hash__(self) -> int: ... +long = int + class float(SupportsFloat, SupportsInt, SupportsAbs[float]): @overload def __init__(self) -> None: ... @@ -210,7 +212,7 @@ class unicode(basestring, Sequence[unicode]): def center(self, width: int, fillchar: unicode = u' ') -> unicode: ... def count(self, x: unicode) -> int: ... def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... - def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> bytes: ... def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = 0, end: int = ...) -> bool: ... def expandtabs(self, tabsize: int = 8) -> unicode: ... @@ -282,7 +284,7 @@ class str(basestring, Sequence[str]): def center(self, width: int, fillchar: str = ...) -> str: ... def count(self, x: unicode) -> int: ... def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... - def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> bytes: ... def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... def expandtabs(self, tabsize: int = 8) -> str: ... def find(self, sub: unicode, start: int = 0, end: int = 0) -> int: ... @@ -366,11 +368,102 @@ class str(basestring, Sequence[str]): def __ge__(self, x: unicode) -> bool: ... def __mod__(self, x: Any) -> str: ... +class bytes(basestring, Sequence[bytes]): + # TODO: double-check unicode, AnyStr, unions, bytearray + def __init__(self, object: object) -> None: ... + def capitalize(self) -> bytes: ... + def center(self, width: int, fillchar: bytes = ...) -> bytes: ... + def count(self, x: unicode) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> bytes: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = 8) -> bytes: ... + def find(self, sub: unicode, start: int = 0, end: int = 0) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> bytes: ... + def index(self, sub: unicode, start: int = 0, end: int = 0) -> 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[AnyStr]) -> AnyStr: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def lower(self) -> bytes: ... + @overload + def lstrip(self, chars: bytes = ...) -> bytes: ... + @overload + def lstrip(self, chars: unicode) -> unicode: ... + @overload + def partition(self, sep: bytearray) -> Tuple[bytes, bytearray, bytes]: ... + @overload + def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + @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: int = 0, end: int = 0) -> int: ... + def rindex(self, sub: unicode, start: int = 0, end: int = 0) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... + @overload + def rpartition(self, sep: bytearray) -> Tuple[bytes, bytearray, bytes]: ... + @overload + def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + @overload + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + @overload + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + @overload + def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + @overload + def rstrip(self, chars: bytes = ...) -> bytes: ... + @overload + def rstrip(self, chars: unicode) -> unicode: ... + @overload + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + @overload + def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[bytes]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + @overload + def strip(self, chars: bytes = ...) -> bytes: ... + @overload + def strip(self, chars: unicode) -> unicode: ... + def swapcase(self) -> bytes: ... + def title(self) -> bytes: ... + def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... + def upper(self) -> bytes: ... + def zfill(self, width: int) -> bytes: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[bytes]: ... + 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) -> bytes: ... + @overload + def __getitem__(self, s: slice) -> bytes: ... + def __getslice__(self, start: int, stop: int) -> bytes: ... + def __add__(self, s: AnyStr) -> AnyStr: ... + def __mul__(self, n: int) -> bytes: ... + def __rmul__(self, n: int) -> bytes: ... + 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 __mod__(self, x: Any) -> bytes: ... + class bytearray(MutableSequence[int]): @overload def __init__(self) -> None: ... @overload - def __init__(self, x: Union[Iterable[int], str]) -> None: ... + def __init__(self, x: Union[Iterable[int], bytes]) -> None: ... @overload def __init__(self, x: unicode, encoding: unicode, errors: unicode = ...) -> None: ... @@ -659,9 +752,6 @@ class property: def __set__(self, obj: Any, value: Any) -> None: ... def __delete__(self, obj: Any) -> None: ... -long = int -bytes = str - NotImplemented = ... # type: Any def abs(n: SupportsAbs[_T]) -> _T: ... @@ -716,11 +806,11 @@ def next(i: Iterator[_T]) -> _T: ... def next(i: Iterator[_T], default: _T) -> _T: ... def oct(i: int) -> str: ... # TODO __index__ @overload -def open(file: str, mode: str = 'r', buffering: int = ...) -> BinaryIO: ... +def open(file: str, mode: str = 'r', buffering: int = ...) -> IO[str]: ... @overload -def open(file: unicode, mode: str = 'r', buffering: int = ...) -> BinaryIO: ... +def open(file: unicode, mode: str = 'r', buffering: int = ...) -> IO[str]: ... @overload -def open(file: int, mode: str = 'r', buffering: int = ...) -> BinaryIO: ... +def open(file: int, mode: str = 'r', buffering: int = ...) -> IO[str]: ... def ord(c: unicode) -> int: ... # This is only available after from __future__ import print_function. def print(*values: Any, sep: unicode = u' ', end: unicode = u'\n', @@ -913,8 +1003,8 @@ class file(BinaryIO): def __init__(self, file: unicode, mode: str = 'r', buffering: int = ...) -> None: ... @overload def __init__(file: int, mode: str = 'r', buffering: int = ...) -> None: ... - def __iter__(self) -> Iterator[str]: ... - def read(self, n: int = ...) -> str: ... + def __iter__(self) -> Iterator[bytes]: ... + def read(self, n: int = ...) -> bytes: ... def __enter__(self) -> BinaryIO: ... def __exit__(self, t: type = None, exc: BaseException = None, tb: Any = None) -> bool: ... def flush(self) -> None: ... @@ -927,10 +1017,10 @@ class file(BinaryIO): def seekable(self) -> bool: ... def seek(self, offset: int, whence: int = ...) -> None: ... def tell(self) -> int: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... - def write(self, data: str) -> None: ... - def writelines(self, data: Iterable[str]) -> None: ... + def readline(self, limit: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def write(self, data: bytes) -> None: ... + def writelines(self, data: Iterable[bytes]) -> None: ... def truncate(self, pos: int = ...) -> int: ... # Very old builtins diff --git a/stdlib/2.7/io.pyi b/stdlib/2.7/io.pyi index 376346333b8d..b6cc6dfd2d5a 100644 --- a/stdlib/2.7/io.pyi +++ b/stdlib/2.7/io.pyi @@ -18,7 +18,7 @@ class IOBase: ... class BytesIO(BinaryIO): - def __init__(self, initial_bytes: str = ...) -> None: ... + def __init__(self, initial_bytes: bytes = ...) -> None: ... # TODO getbuffer # TODO see comments in BinaryIO for missing functionality def close(self) -> None: ... @@ -26,22 +26,22 @@ class BytesIO(BinaryIO): def fileno(self) -> int: ... def flush(self) -> None: ... def isatty(self) -> bool: ... - def read(self, n: int = ...) -> str: ... + def read(self, n: int = ...) -> bytes: ... def readable(self) -> bool: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... + def readline(self, limit: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... def seek(self, offset: int, whence: int = ...) -> None: ... def seekable(self) -> bool: ... def tell(self) -> int: ... def truncate(self, size: int = ...) -> int: ... def writable(self) -> bool: ... - def write(self, s: str) -> None: ... - def writelines(self, lines: Iterable[str]) -> None: ... - def getvalue(self) -> str: ... - def read1(self) -> str: ... + def write(self, s: bytes) -> None: ... + def writelines(self, lines: Iterable[bytes]) -> None: ... + def getvalue(self) -> bytes: ... + def read1(self) -> bytes: ... - def __iter__(self) -> Iterator[str]: ... - def next(self) -> str: ... + def __iter__(self) -> Iterator[bytes]: ... + def next(self) -> bytes: ... def __enter__(self) -> 'BytesIO': ... def __exit__(self, type, value, traceback) -> bool: ... @@ -74,7 +74,7 @@ class StringIO(TextIO): class TextIOWrapper(TextIO): # write_through is undocumented but used by subprocess - def __init__(self, buffer: IO[str], encoding: unicode = ..., + def __init__(self, buffer: IO[bytes], encoding: unicode = ..., errors: unicode = ..., newline: unicode = ..., line_buffering: bool = ..., write_through: bool = ...) -> None: ... diff --git a/stdlib/2.7/re.pyi b/stdlib/2.7/re.pyi index 4c6909436c36..6214dd825d66 100644 --- a/stdlib/2.7/re.pyi +++ b/stdlib/2.7/re.pyi @@ -34,63 +34,63 @@ def compile(pattern: AnyStr, flags: int = ...) -> Pattern[AnyStr]: ... def compile(pattern: Pattern[AnyStr], flags: int = ...) -> Pattern[AnyStr]: ... @overload -def search(pattern: Union[str, unicode], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... +def search(pattern: Union[bytes, str, unicode], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... @overload -def search(pattern: Union[Pattern[str],Pattern[unicode]], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... +def search(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... @overload -def match(pattern: Union[str, unicode], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... +def match(pattern: Union[bytes, str, unicode], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... @overload -def match(pattern: Union[Pattern[str],Pattern[unicode]], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... +def match(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], string: AnyStr, flags: int = ...) -> Match[AnyStr]: ... @overload -def split(pattern: Union[str, unicode], string: AnyStr, +def split(pattern: Union[bytes, str, unicode], string: AnyStr, maxsplit: int = ..., flags: int = ...) -> List[AnyStr]: ... @overload -def split(pattern: Union[Pattern[str],Pattern[unicode]], string: AnyStr, +def split(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], string: AnyStr, maxsplit: int = ..., flags: int = ...) -> List[AnyStr]: ... @overload -def findall(pattern: Union[str, unicode], string: AnyStr, flags: int = ...) -> List[Any]: ... +def findall(pattern: Union[bytes, str, unicode], string: AnyStr, flags: int = ...) -> List[Any]: ... @overload -def findall(pattern: Union[Pattern[str],Pattern[unicode]], string: AnyStr, flags: int = ...) -> List[Any]: ... +def findall(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], string: AnyStr, flags: int = ...) -> List[Any]: ... # Return an iterator yielding match objects over all non-overlapping matches # for the RE pattern in string. The string is scanned left-to-right, and # matches are returned in the order found. Empty matches are included in the # result unless they touch the beginning of another match. @overload -def finditer(pattern: Union[str, unicode], string: AnyStr, +def finditer(pattern: Union[bytes, str, unicode], string: AnyStr, flags: int = ...) -> Iterator[Match[AnyStr]]: ... @overload -def finditer(pattern: Union[Pattern[str],Pattern[unicode]], string: AnyStr, +def finditer(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], string: AnyStr, flags: int = ...) -> Iterator[Match[AnyStr]]: ... @overload -def sub(pattern: Union[str, unicode], repl: AnyStr, string: AnyStr, count: int = ..., +def sub(pattern: Union[bytes, str, unicode], repl: AnyStr, string: AnyStr, count: int = ..., flags: int = ...) -> AnyStr: ... @overload -def sub(pattern: Union[str, unicode], repl: Callable[[Match[AnyStr]], AnyStr], +def sub(pattern: Union[bytes, str, unicode], repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: int = ...) -> AnyStr: ... @overload -def sub(pattern: Union[Pattern[str],Pattern[unicode]], repl: AnyStr, string: AnyStr, count: int = ..., +def sub(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], repl: AnyStr, string: AnyStr, count: int = ..., flags: int = ...) -> AnyStr: ... @overload -def sub(pattern: Union[Pattern[str],Pattern[unicode]], repl: Callable[[Match[AnyStr]], AnyStr], +def sub(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: int = ...) -> AnyStr: ... @overload -def subn(pattern: Union[str, unicode], repl: AnyStr, string: AnyStr, count: int = ..., +def subn(pattern: Union[bytes, str, unicode], repl: AnyStr, string: AnyStr, count: int = ..., flags: int = ...) -> Tuple[AnyStr, int]: ... @overload -def subn(pattern: Union[str, unicode], repl: Callable[[Match[AnyStr]], AnyStr], +def subn(pattern: Union[bytes, str, unicode], repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: int = ...) -> Tuple[AnyStr, int]: ... @overload -def subn(pattern: Union[Pattern[str],Pattern[unicode]], repl: AnyStr, string: AnyStr, count: int = ..., +def subn(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], repl: AnyStr, string: AnyStr, count: int = ..., flags: int = ...) -> Tuple[AnyStr, int]: ... @overload -def subn(pattern: Union[Pattern[str],Pattern[unicode]], repl: Callable[[Match[AnyStr]], AnyStr], +def subn(pattern: Union[Pattern[bytes], Pattern[str], Pattern[unicode]], repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: int = ...) -> Tuple[AnyStr, int]: ... diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index 90a22292df24..38dfd78e0067 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -30,7 +30,7 @@ DefaultDict = TypeAlias(object) Set = TypeAlias(object) # Predefined type variables. -AnyStr = TypeVar('AnyStr', str, unicode) +AnyStr = TypeVar('AnyStr', bytes, str, unicode) # Abstract base classes. @@ -262,7 +262,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): # TODO: traceback should be TracebackType but that's defined in types traceback: Optional[Any]) -> bool: ... -class BinaryIO(IO[str]): +class BinaryIO(IO[bytes]): # TODO readinto # TODO read1? # TODO peek?