Skip to content

Use SupportsIndex where applicable for 4 classes in builtins.pyi #5694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 69 additions & 60 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,16 @@ class str(Sequence[str]):
def __new__(cls: Type[_T], o: bytes, encoding: str = ..., errors: str = ...) -> _T: ...
def capitalize(self) -> str: ...
def casefold(self) -> str: ...
def center(self, __width: int, __fillchar: str = ...) -> str: ...
def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ...
def count(self, x: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ...
def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ...
def endswith(
self, __suffix: Union[str, Tuple[str, ...]], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
) -> bool: ...
def expandtabs(self, tabsize: int = ...) -> str: ...
if sys.version_info >= (3, 8):
def expandtabs(self, tabsize: SupportsIndex = ...) -> str: ...
else:
def expandtabs(self, tabsize: int = ...) -> str: ...
def find(self, __sub: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ...
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, map: _FormatMapMapping) -> str: ...
Expand All @@ -359,21 +362,21 @@ class str(Sequence[str]):
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
def join(self, __iterable: Iterable[str]) -> str: ...
def ljust(self, __width: int, __fillchar: str = ...) -> str: ...
def ljust(self, __width: SupportsIndex, __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 replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ...
if sys.version_info >= (3, 9):
def removeprefix(self, __prefix: str) -> str: ...
def removesuffix(self, __suffix: str) -> str: ...
def rfind(self, __sub: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ...
def rindex(self, __sub: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ...
def rjust(self, __width: int, __fillchar: str = ...) -> str: ...
def rjust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ...
def rpartition(self, __sep: str) -> Tuple[str, str, str]: ...
def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ...
def rsplit(self, sep: Optional[str] = ..., maxsplit: SupportsIndex = ...) -> List[str]: ...
def rstrip(self, __chars: Optional[str] = ...) -> str: ...
def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ...
def split(self, sep: Optional[str] = ..., maxsplit: SupportsIndex = ...) -> List[str]: ...
def splitlines(self, keepends: bool = ...) -> List[str]: ...
def startswith(
self, __prefix: Union[str, Tuple[str, ...]], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
Expand All @@ -383,7 +386,7 @@ class str(Sequence[str]):
def title(self) -> str: ...
def translate(self, __table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ...
def upper(self) -> str: ...
def zfill(self, __width: int) -> str: ...
def zfill(self, __width: SupportsIndex) -> str: ...
@staticmethod
@overload
def maketrans(__x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ...
Expand All @@ -403,28 +406,28 @@ class str(Sequence[str]):
def __len__(self) -> int: ...
def __lt__(self, x: str) -> bool: ...
def __mod__(self, x: Any) -> str: ...
def __mul__(self, n: int) -> str: ...
def __mul__(self, n: SupportsIndex) -> str: ...
def __ne__(self, x: object) -> bool: ...
def __repr__(self) -> str: ...
def __rmul__(self, n: int) -> str: ...
def __rmul__(self, n: SupportsIndex) -> str: ...
def __str__(self) -> str: ...
def __getnewargs__(self) -> Tuple[str]: ...

class bytes(ByteString):
@overload
def __new__(cls: Type[_T], ints: Iterable[int]) -> _T: ...
def __new__(cls: Type[_T], ints: Iterable[SupportsIndex]) -> _T: ...
@overload
def __new__(cls: Type[_T], string: str, encoding: str, errors: str = ...) -> _T: ...
@overload
def __new__(cls: Type[_T], length: int) -> _T: ...
def __new__(cls: Type[_T], length: SupportsIndex) -> _T: ...
@overload
def __new__(cls: Type[_T]) -> _T: ...
@overload
def __new__(cls: Type[_T], o: SupportsBytes) -> _T: ...
def capitalize(self) -> bytes: ...
def center(self, __width: int, __fillchar: bytes = ...) -> bytes: ...
def center(self, __width: SupportsIndex, __fillchar: bytes = ...) -> bytes: ...
def count(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def decode(self, encoding: str = ..., errors: str = ...) -> str: ...
def endswith(
Expand All @@ -433,16 +436,19 @@ class bytes(ByteString):
__start: Optional[SupportsIndex] = ...,
__end: Optional[SupportsIndex] = ...,
) -> bool: ...
def expandtabs(self, tabsize: int = ...) -> bytes: ...
if sys.version_info >= (3, 8):
def expandtabs(self, tabsize: SupportsIndex = ...) -> bytes: ...
else:
def expandtabs(self, tabsize: int = ...) -> bytes: ...
def find(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
if sys.version_info >= (3, 8):
def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: int = ...) -> str: ...
def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: SupportsIndex = ...) -> str: ...
else:
def hex(self) -> str: ...
def index(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def isalnum(self) -> bool: ...
def isalpha(self) -> bool: ...
Expand All @@ -454,25 +460,25 @@ class bytes(ByteString):
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
def join(self, __iterable_of_bytes: Iterable[Union[ByteString, memoryview]]) -> bytes: ...
def ljust(self, __width: int, __fillchar: bytes = ...) -> bytes: ...
def ljust(self, __width: SupportsIndex, __fillchar: bytes = ...) -> bytes: ...
def lower(self) -> bytes: ...
def lstrip(self, __bytes: Optional[bytes] = ...) -> bytes: ...
def partition(self, __sep: bytes) -> Tuple[bytes, bytes, bytes]: ...
def replace(self, __old: bytes, __new: bytes, __count: int = ...) -> bytes: ...
def replace(self, __old: bytes, __new: bytes, __count: SupportsIndex = ...) -> bytes: ...
if sys.version_info >= (3, 9):
def removeprefix(self, __prefix: bytes) -> bytes: ...
def removesuffix(self, __suffix: bytes) -> bytes: ...
def rfind(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def rindex(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def rjust(self, __width: int, __fillchar: bytes = ...) -> bytes: ...
def rjust(self, __width: SupportsIndex, __fillchar: bytes = ...) -> bytes: ...
def rpartition(self, __sep: bytes) -> Tuple[bytes, bytes, bytes]: ...
def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ...
def rsplit(self, sep: Optional[bytes] = ..., maxsplit: SupportsIndex = ...) -> List[bytes]: ...
def rstrip(self, __bytes: Optional[bytes] = ...) -> bytes: ...
def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ...
def split(self, sep: Optional[bytes] = ..., maxsplit: SupportsIndex = ...) -> List[bytes]: ...
def splitlines(self, keepends: bool = ...) -> List[bytes]: ...
def startswith(
self,
Expand All @@ -485,7 +491,7 @@ class bytes(ByteString):
def title(self) -> bytes: ...
def translate(self, __table: Optional[bytes], delete: bytes = ...) -> bytes: ...
def upper(self) -> bytes: ...
def zfill(self, __width: int) -> bytes: ...
def zfill(self, __width: SupportsIndex) -> bytes: ...
@classmethod
def fromhex(cls, __s: str) -> bytes: ...
@staticmethod
Expand All @@ -496,15 +502,15 @@ class bytes(ByteString):
def __repr__(self) -> str: ...
def __hash__(self) -> int: ...
@overload
def __getitem__(self, i: int) -> int: ...
def __getitem__(self, i: SupportsIndex) -> 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: ...
def __mul__(self, n: SupportsIndex) -> bytes: ...
def __rmul__(self, n: SupportsIndex) -> bytes: ...
def __mod__(self, value: Any) -> bytes: ...
# Incompatible with Sequence.__contains__
def __contains__(self, o: Union[int, bytes]) -> bool: ... # type: ignore
def __contains__(self, o: SupportsIndex | bytes) -> bool: ... # type: ignore
def __eq__(self, x: object) -> bool: ...
def __ne__(self, x: object) -> bool: ...
def __lt__(self, x: bytes) -> bool: ...
Expand All @@ -517,16 +523,16 @@ class bytearray(MutableSequence[int], ByteString):
@overload
def __init__(self) -> None: ...
@overload
def __init__(self, ints: Iterable[int]) -> None: ...
def __init__(self, ints: Iterable[SupportsIndex]) -> None: ...
@overload
def __init__(self, string: str, encoding: str, errors: str = ...) -> None: ...
@overload
def __init__(self, length: int) -> None: ...
def append(self, __item: int) -> None: ...
def __init__(self, length: SupportsIndex) -> None: ...
def append(self, __item: SupportsIndex) -> None: ...
def capitalize(self) -> bytearray: ...
def center(self, __width: int, __fillchar: bytes = ...) -> bytearray: ...
def center(self, __width: SupportsIndex, __fillchar: bytes = ...) -> bytearray: ...
def count(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def copy(self) -> bytearray: ...
def decode(self, encoding: str = ..., errors: str = ...) -> str: ...
Expand All @@ -536,19 +542,22 @@ class bytearray(MutableSequence[int], ByteString):
__start: Optional[SupportsIndex] = ...,
__end: Optional[SupportsIndex] = ...,
) -> bool: ...
def expandtabs(self, tabsize: int = ...) -> bytearray: ...
def extend(self, __iterable_of_ints: Iterable[int]) -> None: ...
if sys.version_info >= (3, 8):
def expandtabs(self, tabsize: SupportsIndex = ...) -> bytearray: ...
else:
def expandtabs(self, tabsize: int = ...) -> bytearray: ...
def extend(self, __iterable_of_ints: Iterable[SupportsIndex]) -> None: ...
def find(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
if sys.version_info >= (3, 8):
def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: int = ...) -> str: ...
def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: SupportsIndex = ...) -> str: ...
else:
def hex(self) -> str: ...
def index(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def insert(self, __index: int, __item: int) -> None: ...
def insert(self, __index: SupportsIndex, __item: SupportsIndex) -> None: ...
def isalnum(self) -> bool: ...
def isalpha(self) -> bool: ...
if sys.version_info >= (3, 7):
Expand All @@ -559,25 +568,25 @@ class bytearray(MutableSequence[int], ByteString):
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
def join(self, __iterable_of_bytes: Iterable[Union[ByteString, memoryview]]) -> bytearray: ...
def ljust(self, __width: int, __fillchar: bytes = ...) -> bytearray: ...
def ljust(self, __width: SupportsIndex, __fillchar: bytes = ...) -> bytearray: ...
def lower(self) -> bytearray: ...
def lstrip(self, __bytes: Optional[bytes] = ...) -> bytearray: ...
def partition(self, __sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ...
if sys.version_info >= (3, 9):
def removeprefix(self, __prefix: bytes) -> bytearray: ...
def removesuffix(self, __suffix: bytes) -> bytearray: ...
def replace(self, __old: bytes, __new: bytes, __count: int = ...) -> bytearray: ...
def replace(self, __old: bytes, __new: bytes, __count: SupportsIndex = ...) -> bytearray: ...
def rfind(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def rindex(
self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...
self, __sub: bytes | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
def rjust(self, __width: int, __fillchar: bytes = ...) -> bytearray: ...
def rjust(self, __width: SupportsIndex, __fillchar: bytes = ...) -> bytearray: ...
def rpartition(self, __sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ...
def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ...
def rsplit(self, sep: Optional[bytes] = ..., maxsplit: SupportsIndex = ...) -> List[bytearray]: ...
def rstrip(self, __bytes: Optional[bytes] = ...) -> bytearray: ...
def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ...
def split(self, sep: Optional[bytes] = ..., maxsplit: SupportsIndex = ...) -> List[bytearray]: ...
def splitlines(self, keepends: bool = ...) -> List[bytearray]: ...
def startswith(
self,
Expand All @@ -590,7 +599,7 @@ class bytearray(MutableSequence[int], ByteString):
def title(self) -> bytearray: ...
def translate(self, __table: Optional[bytes], delete: bytes = ...) -> bytearray: ...
def upper(self) -> bytearray: ...
def zfill(self, __width: int) -> bytearray: ...
def zfill(self, __width: SupportsIndex) -> bytearray: ...
@classmethod
def fromhex(cls, __string: str) -> bytearray: ...
@staticmethod
Expand All @@ -601,22 +610,22 @@ class bytearray(MutableSequence[int], ByteString):
def __repr__(self) -> str: ...
__hash__: None # type: ignore
@overload
def __getitem__(self, i: int) -> int: ...
def __getitem__(self, i: SupportsIndex) -> int: ...
@overload
def __getitem__(self, s: slice) -> bytearray: ...
@overload
def __setitem__(self, i: int, x: int) -> None: ...
def __setitem__(self, i: SupportsIndex, x: SupportsIndex) -> None: ...
@overload
def __setitem__(self, s: slice, x: Union[Iterable[int], bytes]) -> None: ...
def __delitem__(self, i: Union[int, slice]) -> None: ...
def __setitem__(self, s: slice, x: Iterable[SupportsIndex] | bytes) -> None: ...
def __delitem__(self, i: SupportsIndex | slice) -> None: ...
def __add__(self, s: bytes) -> bytearray: ...
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: ...
def __mul__(self, n: SupportsIndex) -> bytearray: ...
def __rmul__(self, n: SupportsIndex) -> bytearray: ...
def __imul__(self, n: SupportsIndex) -> bytearray: ...
def __mod__(self, value: Any) -> bytes: ...
# Incompatible with Sequence.__contains__
def __contains__(self, o: Union[int, bytes]) -> bool: ... # type: ignore
def __contains__(self, o: SupportsIndex | bytes) -> bool: ... # type: ignore
def __eq__(self, x: object) -> bool: ...
def __ne__(self, x: object) -> bool: ...
def __lt__(self, x: bytes) -> bool: ...
Expand Down Expand Up @@ -645,7 +654,7 @@ class memoryview(Sized, Sequence[int]):
) -> None: ...
def cast(self, format: str, shape: Union[List[int], Tuple[int]] = ...) -> memoryview: ...
@overload
def __getitem__(self, i: int) -> int: ...
def __getitem__(self, i: SupportsIndex) -> int: ...
@overload
def __getitem__(self, s: slice) -> memoryview: ...
def __contains__(self, x: object) -> bool: ...
Expand All @@ -654,7 +663,7 @@ class memoryview(Sized, Sequence[int]):
@overload
def __setitem__(self, s: slice, o: bytes) -> None: ...
@overload
def __setitem__(self, i: int, o: int) -> None: ...
def __setitem__(self, i: SupportsIndex, o: SupportsIndex) -> None: ...
if sys.version_info >= (3, 8):
def tobytes(self, order: Optional[Literal["C", "F", "A"]] = ...) -> bytes: ...
else:
Expand All @@ -664,7 +673,7 @@ class memoryview(Sized, Sequence[int]):
def toreadonly(self) -> memoryview: ...
def release(self) -> None: ...
if sys.version_info >= (3, 8):
def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: int = ...) -> str: ...
def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: SupportsIndex = ...) -> str: ...
else:
def hex(self) -> str: ...

Expand Down
Loading