More permissive type for random.choice and related functions (#6562)

This commit is contained in:
Jelle Zijlstra
2021-12-10 10:50:02 -08:00
committed by GitHub
parent 74ecc2904b
commit 943dc5f61d
2 changed files with 12 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
import _random
import sys
from _typeshed import SupportsLenAndGetItem
from collections.abc import Callable, Iterable, MutableSequence, Sequence
from fractions import Fraction
from typing import Any, ClassVar, NoReturn, Tuple, TypeVar
@@ -17,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: Sequence[_T]) -> _T: ...
def choice(self, seq: SupportsLenAndGetItem[_T]) -> _T: ...
def choices(
self,
population: Sequence[_T],
population: SupportsLenAndGetItem[_T],
weights: Sequence[float | Fraction] | None = ...,
*,
cum_weights: Sequence[float | Fraction] | None = ...,
@@ -61,9 +62,13 @@ def randint(a: int, b: int) -> int: ...
if sys.version_info >= (3, 9):
def randbytes(n: int) -> bytes: ...
def choice(seq: Sequence[_T]) -> _T: ...
def choice(seq: SupportsLenAndGetItem[_T]) -> _T: ...
def choices(
population: Sequence[_T], weights: Sequence[float] | None = ..., *, cum_weights: Sequence[float] | None = ..., k: int = ...
population: SupportsLenAndGetItem[_T],
weights: Sequence[float] | None = ...,
*,
cum_weights: Sequence[float] | None = ...,
k: int = ...,
) -> list[_T]: ...
def shuffle(x: MutableSequence[Any], random: Callable[[], float] | None = ...) -> None: ...