bpo-40465: Deprecate the optional argument to random.shuffle(). (#19867)

This commit is contained in:
Raymond Hettinger 2020-05-02 16:45:32 -07:00 committed by GitHub
parent 766352320f
commit 190fac99c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 1 deletions

View File

@ -208,6 +208,9 @@ Functions for sequences
generated. For example, a sequence of length 2080 is the largest that
can fit within the period of the Mersenne Twister random number generator.
.. deprecated-removed:: 3.9 3.11
The optional parameter *random*.
.. function:: sample(population, k)

View File

@ -321,6 +321,10 @@ class Random(_random.Random):
j = randbelow(i+1)
x[i], x[j] = x[j], x[i]
else:
_warn('The *random* parameter to shuffle() has been deprecated\n'
'since Python 3.9 and will be removed in a subsequent '
'version.',
DeprecationWarning, 2)
_int = int
for i in reversed(range(1, len(x))):
# pick an element in x[:i+1] with which to exchange x[i]

View File

@ -103,6 +103,7 @@ class TestBasicOps:
shuffle = self.gen.shuffle
mock_random = unittest.mock.Mock(return_value=0.5)
seq = bytearray(b'abcdefghijk')
with self.assertWarns(DeprecationWarning):
shuffle(seq, mock_random)
mock_random.assert_called_with()

View File

@ -0,0 +1 @@
Deprecated the optional *random* argument to *random.shuffle()*.