bpo-33203: Ensure random.choice always raises IndexError on empty sequence#6338
bpo-33203: Ensure random.choice always raises IndexError on empty sequence#6338rhettinger merged 2 commits intopython:masterfrom
Conversation
Without this patch a ZeroDivisionError was leaked for Random subclasses overriding the random, but not the getrandbits method.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Are there high-level tests for choice([]) and other implicit calls of _randbelow(0)?
| "enough bits to choose from a population range this large.\n" | ||
| "To remove the range limitation, add a getrandbits() method.") | ||
| return int(random() * n) | ||
| if n == 0: |
There was a problem hiding this comment.
The condition n == 0 mirrors the docstring, Raises ValueError if n==0."
|
I'm not aware of any other place calling |
|
If running code with the |
|
@selik: I'm not sure I understand the problem with the |
rhettinger
left a comment
There was a problem hiding this comment.
This all looks fine to me. Please add a NEWS blurb.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
@wm75 Sorry, I misread the |
|
@rhettinger I have made the requested changes; please review again |
|
Thanks for making the requested changes! @rhettinger: please review the changes made to this pull request. |
|
Thanks @wm75 for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
|
GH-6387 is a backport of this pull request to the 3.7 branch. |
…uence (pythonGH-6338) (cherry picked from commit 091e95e) Co-authored-by: Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
…uence (pythonGH-6338) (cherry picked from commit 091e95e) Co-authored-by: Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
|
GH-6388 is a backport of this pull request to the 3.6 branch. |
Without this patch a ZeroDivisionError was leaked for Random
subclasses overriding the random, but not the getrandbits method.
https://bugs.python.org/issue33203