summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authormasklinn <github.com@masklinn.net>2020-12-19 04:33:36 (GMT)
committerGitHub <noreply@github.com>2020-12-19 04:33:36 (GMT)
commit1e27b57dbc8c1b758e37a531487813aef2d111ca (patch)
tree4f7b7740e4f6739e9c053a5369f56ae2e8e9b05e /Lib/random.py
parente0096124768f5d06b78cec977d9c37f27c5eab5f (diff)
downloadcpython-1e27b57dbc8c1b758e37a531487813aef2d111ca.zip
cpython-1e27b57dbc8c1b758e37a531487813aef2d111ca.tar.gz
cpython-1e27b57dbc8c1b758e37a531487813aef2d111ca.tar.bz2
bpo-42470: Do not warn on sequences which are also sets in random.sample() (GH-23665)
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 139e8a4..66433ba 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -424,13 +424,14 @@ class Random(_random.Random):
# too many calls to _randbelow(), making them slower and
# 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. For dicts or sets, use sorted(d).")
+ 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)
+ else:
+ raise TypeError("Population must be a sequence. For dicts or sets, use sorted(d).")
n = len(population)
if counts is not None:
cum_counts = list(_accumulate(counts))