diff options
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 13 |
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)) |