From eb252afb18d1179851865ccf37f1fa7bf0317e2e Mon Sep 17 00:00:00 2001 From: Harry Date: Tue, 22 Mar 2022 01:58:22 +0000 Subject: [PATCH] random.sample no longer accepts sets in Python 3.11 (#7528) As of 3.11, population must be a Sequence. Automatic conversion of sets to lists is no longer supported. --- stdlib/random.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/random.pyi b/stdlib/random.pyi index b9a35a6b4..612a54cb9 100644 --- a/stdlib/random.pyi +++ b/stdlib/random.pyi @@ -90,7 +90,9 @@ class Random(_random.Random): k: int = ..., ) -> list[_T]: ... def shuffle(self, x: MutableSequence[Any], random: Callable[[], float] | None = ...) -> None: ... - if sys.version_info >= (3, 9): + if sys.version_info >= (3, 11): + def sample(self, population: Sequence[_T], k: int, *, counts: Iterable[int] | None = ...) -> list[_T]: ... + elif sys.version_info >= (3, 9): def sample( self, population: Sequence[_T] | AbstractSet[_T], k: int, *, counts: Iterable[int] | None = ... ) -> list[_T]: ...