mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 04:34:28 +08:00
More permissive type for random.choice and related functions (#6562)
This commit is contained in:
@@ -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: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user