mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
bpo-42470: Do not warn on sequences which are also sets in random.sample() (GH-23665)
This commit is contained in:
parent
e009612476
commit
1e27b57dbc
3 changed files with 25 additions and 7 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue