summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2020-05-02 23:45:32 (GMT)
committerGitHub <noreply@github.com>2020-05-02 23:45:32 (GMT)
commit190fac99c58232f3e0b34891872b91e50ea2f057 (patch)
tree13a0e6733986b407a8f7898f2a1829552d96e425
parent766352320fd736e2c8ed545b4cc57563f61a0b9d (diff)
downloadcpython-190fac99c58232f3e0b34891872b91e50ea2f057.zip
cpython-190fac99c58232f3e0b34891872b91e50ea2f057.tar.gz
cpython-190fac99c58232f3e0b34891872b91e50ea2f057.tar.bz2
bpo-40465: Deprecate the optional argument to random.shuffle(). (#19867)
-rw-r--r--Doc/library/random.rst3
-rw-r--r--Lib/random.py4
-rw-r--r--Lib/test/test_random.py3
-rw-r--r--Misc/NEWS.d/next/Library/2020-05-02-12-00-28.bpo-40465.qfCjOD.rst1
4 files changed, 10 insertions, 1 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 291eca3..43a9902 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -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)
diff --git a/Lib/random.py b/Lib/random.py
index 8f840e1..f2c4f39 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -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]
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 6d87d21..bb95ca0 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -103,7 +103,8 @@ class TestBasicOps:
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):
diff --git a/Misc/NEWS.d/next/Library/2020-05-02-12-00-28.bpo-40465.qfCjOD.rst b/Misc/NEWS.d/next/Library/2020-05-02-12-00-28.bpo-40465.qfCjOD.rst
new file mode 100644
index 0000000..7ce9a44
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-05-02-12-00-28.bpo-40465.qfCjOD.rst
@@ -0,0 +1 @@
+Deprecated the optional *random* argument to *random.shuffle()*.