From d13eb937f769f3d33042ee300a88ababa201051c Mon Sep 17 00:00:00 2001 From: Paul Dagnelie Date: Thu, 16 May 2019 21:55:57 -0700 Subject: [PATCH] Implement SupportsIndex (#2996) --- stdlib/2/__builtin__.pyi | 10 +++++++--- stdlib/2and3/builtins.pyi | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 8ac0056f9..13a6ef968 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1105,7 +1105,11 @@ 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: ... + +class _SupportsIndex(Protocol): + def __index__(self) -> int: ... +def bin(__number: Union[int, _SupportsIndex]) -> str: ... + if sys.version_info >= (3, 7): def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(__o: object) -> bool: ... @@ -1166,7 +1170,7 @@ 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 hex(__i: Union[int, _SupportsIndex]) -> str: ... def id(__o: object) -> int: ... if sys.version_info >= (3,): def input(__prompt: Any = ...) -> str: ... @@ -1311,7 +1315,7 @@ else: def next(__i: Iterator[_T]) -> _T: ... @overload def next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... -def oct(__i: int) -> str: ... # TODO __index__ +def oct(__i: Union[int, _SupportsIndex]) -> str: ... if sys.version_info >= (3, 6): def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 8ac0056f9..13a6ef968 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -1105,7 +1105,11 @@ 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: ... + +class _SupportsIndex(Protocol): + def __index__(self) -> int: ... +def bin(__number: Union[int, _SupportsIndex]) -> str: ... + if sys.version_info >= (3, 7): def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(__o: object) -> bool: ... @@ -1166,7 +1170,7 @@ 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 hex(__i: Union[int, _SupportsIndex]) -> str: ... def id(__o: object) -> int: ... if sys.version_info >= (3,): def input(__prompt: Any = ...) -> str: ... @@ -1311,7 +1315,7 @@ else: def next(__i: Iterator[_T]) -> _T: ... @overload def next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... -def oct(__i: int) -> str: ... # TODO __index__ +def oct(__i: Union[int, _SupportsIndex]) -> str: ... if sys.version_info >= (3, 6): def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ...,