From 87dcb170cedbf4f824012e379a49039c0929fafd Mon Sep 17 00:00:00 2001 From: Udi Fuchs Date: Sun, 24 Jan 2021 08:07:31 -0600 Subject: [PATCH] Add SupportsIndex to list indexing. (#4804) --- stdlib/3/builtins.pyi | 6 +++--- third_party/2and3/werkzeug/datastructures.pyi | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index d46a08dc0..200711781 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -726,14 +726,14 @@ class list(MutableSequence[_T], Generic[_T]): def __str__(self) -> str: ... __hash__: None # type: ignore @overload - def __getitem__(self, i: int) -> _T: ... + def __getitem__(self, i: _SupportsIndex) -> _T: ... @overload def __getitem__(self, s: slice) -> List[_T]: ... @overload - def __setitem__(self, i: int, o: _T) -> None: ... + def __setitem__(self, i: _SupportsIndex, o: _T) -> None: ... @overload def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... - def __delitem__(self, i: Union[int, slice]) -> None: ... + def __delitem__(self, i: Union[_SupportsIndex, slice]) -> None: ... def __add__(self, x: List[_T]) -> List[_T]: ... def __iadd__(self: _S, x: Iterable[_T]) -> _S: ... def __mul__(self, n: int) -> List[_T]: ... diff --git a/third_party/2and3/werkzeug/datastructures.pyi b/third_party/2and3/werkzeug/datastructures.pyi index d04de7ce6..046e669cb 100644 --- a/third_party/2and3/werkzeug/datastructures.pyi +++ b/third_party/2and3/werkzeug/datastructures.pyi @@ -1,3 +1,4 @@ +import sys from _typeshed import SupportsWrite from typing import ( IO, @@ -21,6 +22,11 @@ from typing import ( overload, ) +if sys.version_info >= (3, 8): + from typing import SupportsIndex +else: + from typing_extensions import SupportsIndex + _K = TypeVar("_K") _V = TypeVar("_V") _R = TypeVar("_R") @@ -264,7 +270,7 @@ class Accept(ImmutableList[Tuple[str, float]]): provided: bool def __init__(self, values: Union[None, Accept, Iterable[Tuple[str, float]]] = ...) -> None: ... @overload - def __getitem__(self, key: int) -> Tuple[str, float]: ... + def __getitem__(self, key: SupportsIndex) -> Tuple[str, float]: ... @overload def __getitem__(self, s: slice) -> List[Tuple[str, float]]: ... @overload