summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2020-04-19 07:36:42 (GMT)
committerGitHub <noreply@github.com>2020-04-19 07:36:42 (GMT)
commit4fe002045fcf40823154b709fef0948b2bc5e934 (patch)
treeea9d2c899b682f91fd21f50c13bfae8903f58f11 /Lib/random.py
parent482259d0dcf27714a84cf56b93977320bea7e093 (diff)
downloadcpython-4fe002045fcf40823154b709fef0948b2bc5e934.zip
cpython-4fe002045fcf40823154b709fef0948b2bc5e934.tar.gz
cpython-4fe002045fcf40823154b709fef0948b2bc5e934.tar.bz2
bpo-40325: Deprecate set object support in random.sample() (GH-19591)
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 3243938..f1df18d 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -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: