Skip to content

Commit

Permalink
bpo-40465: Deprecate the optional argument to random.shuffle(). (pyth…
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger authored May 2, 2020
1 parent 7663523 commit 190fac9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Doc/library/random.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ def shuffle(self, x, random=None):
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]
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def test_shuffle_random_argument(self):
shuffle = self.gen.shuffle
mock_random = unittest.mock.Mock(return_value=0.5)
seq = bytearray(b'abcdefghijk')
shuffle(seq, mock_random)
with self.assertWarns(DeprecationWarning):
shuffle(seq, mock_random)
mock_random.assert_called_with()

def test_choice(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecated the optional *random* argument to *random.shuffle()*.

0 comments on commit 190fac9

Please sign in to comment.