bpo-40325: Deprecate set object support in random.sample() (GH-19591)

This commit is contained in:
Raymond Hettinger 2020-04-19 00:36:42 -07:00 committed by GitHub
parent 482259d0dc
commit 4fe002045f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View file

@ -367,9 +367,12 @@ class Random(_random.Random):
# causing them to eat more entropy than necessary.
if isinstance(population, _Set):
_warn('Sampling from a set deprecated\n'
'since Python 3.9 and will be removed in a subsequent version.',
DeprecationWarning, 2)
population = tuple(population)
if not isinstance(population, _Sequence):
raise TypeError("Population must be a sequence or set. For dicts, use list(d).")
raise TypeError("Population must be a sequence. For dicts or sets, use sorted(d).")
randbelow = self._randbelow
n = len(population)
if not 0 <= k <= n: