From 735df3c31200bb57cc89dcf749dd85e0d846a63f Mon Sep 17 00:00:00 2001 From: George King Date: Mon, 27 Mar 2017 17:41:34 -0400 Subject: [PATCH] Change builtin method signatures to be compatible with Sequence, at the expense of accuracy. --- stdlib/3/builtins.pyi | 65 ++++++++++++++++++++++--------------------- stdlib/3/typing.pyi | 4 +-- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 2b0f40249a87..7aeea855d1f7 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -221,15 +221,15 @@ class str(Sequence[str]): def __init__(self, o: bytes, encoding: str = ..., errors: str = 'strict') -> None: ... def capitalize(self) -> str: ... def center(self, width: int, fillchar: str = ' ') -> str: ... - def count(self, x: str) -> int: ... + def count(self, x: str, start: int = None, stop: int = None) -> int: ... # TODO: __index__ def encode(self, encoding: str = 'utf-8', errors: str = 'strict') -> bytes: ... def endswith(self, suffix: Union[str, Tuple[str, ...]], start: int = None, - end: int = None) -> bool: ... + end: int = None) -> bool: ... # TODO: __index__ def expandtabs(self, tabsize: int = 8) -> str: ... - def find(self, sub: str, start: int = 0, end: int = 0) -> int: ... + def find(self, sub: str, start: int = None, end: int = None) -> int: ... # TODO: __index__ def format(self, *args: Any, **kwargs: Any) -> str: ... def format_map(self, map: Mapping[str, Any]) -> str: ... - def index(self, sub: str, start: int = 0, end: int = 0) -> int: ... + def index(self, sub: str, start: int = None, end: int = None) -> int: ... # TODO: __index__ def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... def isdecimal(self) -> bool: ... @@ -247,8 +247,8 @@ class str(Sequence[str]): def lstrip(self, chars: str = None) -> str: ... def partition(self, sep: str) -> Tuple[str, str, str]: ... def replace(self, old: str, new: str, count: int = -1) -> str: ... - def rfind(self, sub: str, start: int = 0, end: int = 0) -> int: ... - def rindex(self, sub: str, start: int = 0, end: int = 0) -> int: ... + def rfind(self, sub: str, start: int = None, end: int = None) -> int: ... # TODO: __index__ + def rindex(self, sub: str, start: int = None, end: int = None) -> int: ... # TODO: __index__ def rjust(self, width: int, fillchar: str = ' ') -> str: ... def rpartition(self, sep: str) -> Tuple[str, str, str]: ... def rsplit(self, sep: str = None, maxsplit: int = -1) -> List[str]: ... @@ -256,7 +256,7 @@ class str(Sequence[str]): def split(self, sep: str = None, maxsplit: int = -1) -> List[str]: ... def splitlines(self, keepends: bool = ...) -> List[str]: ... def startswith(self, prefix: Union[str, Tuple[str, ...]], start: int = None, - end: int = None) -> bool: ... + end: int = None) -> bool: ... # TODO: __index__ def strip(self, chars: str = None) -> str: ... def swapcase(self) -> str: ... def title(self) -> str: ... @@ -306,22 +306,22 @@ class bytes(ByteString): def capitalize(self) -> bytes: ... def center(self, width: int, fillchar: bytes = ...) -> bytes: ... if sys.version_info >= (3, 3): - def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def count(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def count(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ def decode(self, encoding: str = 'utf-8', errors: str = 'strict') -> str: ... def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def expandtabs(self, tabsize: int = 8) -> bytes: ... if sys.version_info >= (3, 3): - def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def find(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def find(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ if sys.version_info >= (3, 5): def hex(self) -> str: ... if sys.version_info >= (3, 3): - def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def index(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def index(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... def isdigit(self) -> bool: ... @@ -336,13 +336,13 @@ class bytes(ByteString): def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... def replace(self, old: bytes, new: bytes, count: int = -1) -> bytes: ... if sys.version_info >= (3, 3): - def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ if sys.version_info >= (3, 3): - def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... def rsplit(self, sep: bytes = None, maxsplit: int = -1) -> List[bytes]: ... @@ -395,22 +395,22 @@ class bytearray(MutableSequence[int], ByteString): def capitalize(self) -> bytearray: ... def center(self, width: int, fillchar: bytes = ...) -> bytearray: ... if sys.version_info >= (3, 3): - def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def count(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def count(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ def decode(self, encoding: str = 'utf-8', errors: str = 'strict') -> str: ... def endswith(self, suffix: bytes) -> bool: ... def expandtabs(self, tabsize: int = 8) -> bytearray: ... if sys.version_info >= (3, 3): - def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def find(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def find(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ if sys.version_info >= (3, 5): def hex(self) -> str: ... if sys.version_info >= (3, 3): - def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def index(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def index(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ def insert(self, index: int, object: int) -> None: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -426,13 +426,13 @@ class bytearray(MutableSequence[int], ByteString): def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... def replace(self, old: bytes, new: bytes, count: int = -1) -> bytearray: ... if sys.version_info >= (3, 3): - def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ if sys.version_info >= (3, 3): - def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... # TODO: __index__ else: - def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ... # TODO: __index__ def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ... def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... def rsplit(self, sep: bytes = None, maxsplit: int = -1) -> List[bytearray]: ... @@ -525,7 +525,7 @@ class slice: @overload def __init__(self, stop: Optional[int]) -> None: ... @overload - def __init__(self, start: Optional[int], stop: Optional[int], step: int = None) -> None: ... + def __init__(self, start: Optional[int], stop: int = None, step: int = None) -> None: ... def indices(self, len: int) -> Tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): @@ -546,7 +546,8 @@ class tuple(Sequence[_T_co], Generic[_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 = 0, end: int = 0) -> int: ... + def index(self, x: Any, start: int = None, end: int = None) -> int: ... # TODO: __index__ + # NOTE: tuple does not actually support None start/end, but it should to be compatible with Sequence. else: def index(self, x: Any) -> int: ... @@ -568,7 +569,8 @@ class list(MutableSequence[_T], Generic[_T]): def append(self, object: _T) -> None: ... def extend(self, iterable: Iterable[_T]) -> None: ... def pop(self, index: int = -1) -> _T: ... - def index(self, object: _T, start: int = 0, stop: int = ...) -> int: ... + def index(self, object: _T, start: int = None, stop: int = None) -> int: ... # TODO: __index__ + # NOTE: list does not actually support None start/stop, but it should to be compatible with Sequence. def count(self, object: _T) -> int: ... def insert(self, index: int, object: _T) -> None: ... def remove(self, object: _T) -> None: ... @@ -707,7 +709,8 @@ class range(Sequence[int]): @overload def __init__(self, start: int, stop: int, step: int = 1) -> None: ... def count(self, value: int) -> int: ... - def index(self, value: int, start: int = 0, stop: int = None) -> int: ... + def index(self, value: int, start: int = None, end: int = None) -> int: ... # TODO: __index__ + # NOTE: range does not actually have start/end parameters, but it should to be compatible with Sequence. def __len__(self) -> int: ... def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[int]: ... diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 532be44c9132..2ad5533049b6 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -195,7 +195,7 @@ class Sequence(_Collection[_T_co], Reversible[_T_co], Generic[_T_co]): def __getitem__(self, s: slice) -> Sequence[_T_co]: ... # Mixin methods if sys.version_info >= (3, 5): - def index(self, x: Any, start: int = 0, end: int = 0) -> int: ... + def index(self, x: Any, start: int = None, end: int = None) -> int: ... # TODO: __index__ else: def index(self, x: Any) -> int: ... def count(self, x: Any) -> int: ... @@ -438,7 +438,7 @@ class Match(Generic[AnyStr]): class Pattern(Generic[AnyStr]): flags = 0 - groupindex = ... # type: Mapping[str, int] + groupindex = ... # type: Mapping[str, int] groups = 0 pattern = ... # type: AnyStr