From 0209b6f95f54948eb403e395cca75f183b83c76c Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Mon, 7 Jun 2021 06:39:31 +0200 Subject: [PATCH] random.choices: weights can be Fractions (#5587) --- stdlib/random.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/random.pyi b/stdlib/random.pyi index 0f1e28049..152dc906e 100644 --- a/stdlib/random.pyi +++ b/stdlib/random.pyi @@ -1,6 +1,7 @@ import _random import sys from collections.abc import Callable, Iterable, MutableSequence, Sequence, Set +from fractions import Fraction from typing import Any, NoReturn, Optional, Tuple, TypeVar, Union _T = TypeVar("_T") @@ -19,9 +20,9 @@ class Random(_random.Random): def choices( self, population: Sequence[_T], - weights: Optional[Sequence[float]] = ..., + weights: Optional[Sequence[Union[float, Fraction]]] = ..., *, - cum_weights: Optional[Sequence[float]] = ..., + cum_weights: Optional[Sequence[Union[float, Fraction]]] = ..., k: int = ..., ) -> list[_T]: ... def shuffle(self, x: MutableSequence[Any], random: Optional[Callable[[], float]] = ...) -> None: ...