Skip to content

rename _typeshed.SupportsLenAndGetItem to GetItemAndLenSequence #6563

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

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Expand Down
4 changes: 2 additions & 2 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,7 +17,6 @@ from _typeshed import (
SupportsGreaterThan,
SupportsGreaterThanT,
SupportsKeysAndGetItem,
SupportsLenAndGetItem,
SupportsLessThan,
SupportsLessThanT,
SupportsNext,
Expand Down Expand Up @@ -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: ...

Expand Down
10 changes: 5 additions & 5 deletions stdlib/random.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/secrets.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...