diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index a7f8c5147103..63d41bb6304f 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -61,6 +61,15 @@ class SupportsDivMod(Protocol[_T_contra, _T_co]): class SupportsRDivMod(Protocol[_T_contra, _T_co]): def __rdivmod__(self, __other: _T_contra) -> _T_co: ... +# This represents a sequence as defined in the Python documentation: +# https://docs.python.org/3/glossary.html#term-sequence +# collections.abc.Sequence and typing.Sequence are not protocols and +# have additional fields that are often unnecessary. +class SimpleSequence(Protocol[_T_co]): + def __len__(self) -> int: ... + def __getitem__(self, __k: int) -> _T_co: ... + +# obsolete, use SimpleSequence instead class SupportsLenAndGetItem(Protocol[_T_co]): def __len__(self) -> int: ... def __getitem__(self, __k: int) -> _T_co: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index c8f32b2dca0e..1dc22e4185aa 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -10,11 +10,11 @@ from _typeshed import ( OpenTextMode, ReadableBuffer, Self, + SimpleSequence, StrOrBytesPath, SupportsAnext, SupportsDivMod, SupportsKeysAndGetItem, - SupportsLenAndGetItem, SupportsNext, SupportsRDivMod, SupportsRichComparison, @@ -1367,7 +1367,7 @@ class reversed(Iterator[_T], Generic[_T]): @overload def __init__(self, __sequence: Reversible[_T]) -> None: ... @overload - def __init__(self, __sequence: SupportsLenAndGetItem[_T]) -> None: ... + def __init__(self, __sequence: SimpleSequence[_T]) -> None: ... def __iter__(self) -> Iterator[_T]: ... def __next__(self) -> _T: ...