[Python-checkins] cpython (merge 3.6 -> default): merge

raymond.hettinger python-checkins at python.org
Mon Nov 21 17:34:57 EST 2016


https://hg.python.org/cpython/rev/671c032e4fd9
changeset:   105307:671c032e4fd9
parent:      105305:23140bd66d86
parent:      105306:89f95c78e0ab
user:        Raymond Hettinger <python at rcn.com>
date:        Mon Nov 21 14:34:51 2016 -0800
summary:
  merge

files:
  Lib/random.py           |  2 +-
  Lib/test/test_random.py |  1 +
  2 files changed, 2 insertions(+), 1 deletions(-)


diff --git a/Lib/random.py b/Lib/random.py
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -314,7 +314,7 @@
         randbelow = self._randbelow
         n = len(population)
         if not 0 <= k <= n:
-            raise ValueError("Sample larger than population")
+            raise ValueError("Sample larger than population or is negative")
         result = [None] * k
         setsize = 21        # size of a small set minus size of an empty list
         if k > 5:
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -110,6 +110,7 @@
         self.assertEqual(self.gen.sample([], 0), [])  # test edge case N==k==0
         # Exception raised if size of sample exceeds that of population
         self.assertRaises(ValueError, self.gen.sample, population, N+1)
+        self.assertRaises(ValueError, self.gen.sample, [], -1)
 
     def test_sample_distribution(self):
         # For the entire allowable range of 0 <= k <= N, validate that

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list