diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 8c0005294bf0..ff76d207b35e 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -51,10 +51,12 @@ class SupportsDivMod(Protocol[_T_contra, _T_co]): class SupportsRDivMod(Protocol[_T_contra, _T_co]): def __rdivmod__(self, __other: _T_contra) -> _T_co: ... -class SupportsLenAndGetItem(Protocol[_T_co]): +class GetItemAndLenSequence(Protocol[_T_co]): def __len__(self) -> int: ... def __getitem__(self, __k: int) -> _T_co: ... +SupportsLenAndGetItem = GetItemAndLenSequence # backwards compat for annoy stubs + class SupportsTrunc(Protocol): def __trunc__(self) -> int: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index e0a3edf60059..db10d26595ce 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -3,6 +3,7 @@ import types from _ast import AST from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import ( + GetItemAndLenSequence, OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, @@ -16,7 +17,6 @@ from _typeshed import ( SupportsGreaterThan, SupportsGreaterThanT, SupportsKeysAndGetItem, - SupportsLenAndGetItem, SupportsLessThan, SupportsLessThanT, SupportsNext, @@ -1363,7 +1363,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: GetItemAndLenSequence[_T]) -> None: ... def __iter__(self) -> Iterator[_T]: ... def __next__(self) -> _T: ... diff --git a/stdlib/random.pyi b/stdlib/random.pyi index fd449ee1b1ae..dc9af9e9912d 100644 --- a/stdlib/random.pyi +++ b/stdlib/random.pyi @@ -1,6 +1,6 @@ import _random import sys -from _typeshed import SupportsLenAndGetItem +from _typeshed import GetItemAndLenSequence from collections.abc import Callable, Iterable, MutableSequence, Sequence from fractions import Fraction from typing import Any, ClassVar, NoReturn, Tuple, TypeVar @@ -18,10 +18,10 @@ class Random(_random.Random): def randint(self, a: int, b: int) -> int: ... if sys.version_info >= (3, 9): def randbytes(self, n: int) -> bytes: ... - def choice(self, seq: SupportsLenAndGetItem[_T]) -> _T: ... + def choice(self, seq: GetItemAndLenSequence[_T]) -> _T: ... def choices( self, - population: SupportsLenAndGetItem[_T], + population: GetItemAndLenSequence[_T], weights: Sequence[float | Fraction] | None = ..., *, cum_weights: Sequence[float | Fraction] | None = ..., @@ -62,9 +62,9 @@ def randint(a: int, b: int) -> int: ... if sys.version_info >= (3, 9): def randbytes(n: int) -> bytes: ... -def choice(seq: SupportsLenAndGetItem[_T]) -> _T: ... +def choice(seq: GetItemAndLenSequence[_T]) -> _T: ... def choices( - population: SupportsLenAndGetItem[_T], + population: GetItemAndLenSequence[_T], weights: Sequence[float] | None = ..., *, cum_weights: Sequence[float] | None = ..., diff --git a/stdlib/secrets.pyi b/stdlib/secrets.pyi index f57eef8492d7..d2d31d4fa8e7 100644 --- a/stdlib/secrets.pyi +++ b/stdlib/secrets.pyi @@ -1,4 +1,4 @@ -from _typeshed import SupportsLenAndGetItem +from _typeshed import GetItemAndLenSequence from hmac import compare_digest as compare_digest from random import SystemRandom as SystemRandom from typing import TypeVar @@ -7,7 +7,7 @@ _T = TypeVar("_T") def randbelow(exclusive_upper_bound: int) -> int: ... def randbits(k: int) -> int: ... -def choice(seq: SupportsLenAndGetItem[_T]) -> _T: ... +def choice(seq: GetItemAndLenSequence[_T]) -> _T: ... def token_bytes(nbytes: int | None = ...) -> bytes: ... def token_hex(nbytes: int | None = ...) -> str: ... def token_urlsafe(nbytes: int | None = ...) -> str: ...