Skip to content

Commit 190fac9

Browse files
authored
bpo-40465: Deprecate the optional argument to random.shuffle(). (#19867)
1 parent 7663523 commit 190fac9

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Doc/library/random.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ Functions for sequences
208208
generated. For example, a sequence of length 2080 is the largest that
209209
can fit within the period of the Mersenne Twister random number generator.
210210

211+
.. deprecated-removed:: 3.9 3.11
212+
The optional parameter *random*.
213+
211214

212215
.. function:: sample(population, k)
213216

Lib/random.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ def shuffle(self, x, random=None):
321321
j = randbelow(i+1)
322322
x[i], x[j] = x[j], x[i]
323323
else:
324+
_warn('The *random* parameter to shuffle() has been deprecated\n'
325+
'since Python 3.9 and will be removed in a subsequent '
326+
'version.',
327+
DeprecationWarning, 2)
324328
_int = int
325329
for i in reversed(range(1, len(x))):
326330
# pick an element in x[:i+1] with which to exchange x[i]

Lib/test/test_random.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def test_shuffle_random_argument(self):
103103
shuffle = self.gen.shuffle
104104
mock_random = unittest.mock.Mock(return_value=0.5)
105105
seq = bytearray(b'abcdefghijk')
106-
shuffle(seq, mock_random)
106+
with self.assertWarns(DeprecationWarning):
107+
shuffle(seq, mock_random)
107108
mock_random.assert_called_with()
108109

109110
def test_choice(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecated the optional *random* argument to *random.shuffle()*.

0 commit comments

Comments
 (0)