[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-05 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset e25af930a300c01aa043745058a8c7f6c32d89ae by Raymond Hettinger (Miss Islington (bot)) in branch '3.6': bpo-33203: Ensure random.choice always raises IndexError on empty sequence (GH-6338) (GH-6388)

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset baf304e82e1b54dbeee6b78ddf168e33ed8d557a by Raymond Hettinger (Miss Islington (bot)) in branch '3.7': bpo-33203: Ensure random.choice always raises IndexError on empty sequence (GH-6338) (GH-6387)

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-05 Thread miss-islington
Change by miss-islington : -- pull_requests: +6097 ___ Python tracker ___

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-05 Thread miss-islington
Change by miss-islington : -- pull_requests: +6096 ___ Python tracker ___

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 091e95e9004b794280ab35becec2c3e30dd5e96e by Raymond Hettinger (Wolfgang Maier) in branch 'master': bpo-33203: Ensure random.choice always raises IndexError on empty sequence (GH-6338)

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: The patch looks fine. Once a news blurb is added, it can go forward. -- ___ Python tracker

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-04 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg314956 ___ Python tracker ___

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: I think this can go forward as-is. -- ___ Python tracker ___

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-03 Thread Wolfgang Maier
Wolfgang Maier added the comment: @selik: it's true _randbelow doesn't work for negative numbers, but the difference is that both branches are affected, the docstring does not make any guarantees about it, and no public part of the random module is

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-03 Thread Wolfgang Maier
Wolfgang Maier added the comment: @rhettinger: the reason the ValueError gets raised correctly in the getrandbits-dependent branch is because getrandbits itself does a n<=0 check (in C for random.Random, in Python for random.SystemRandom). So I thought

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: I'll mull this over for while. There is some merit in getting the various components to fit together more uniformly. There's also the option of having choice() catch either a ZeroDivisionError or ValueError. --

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, it was intended that the error checking (when required) occur at higher levels in the API rather than in the inner-most non-public utility function. Some calls to _randbelow cannot be zero or negative, so they shouldn't

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-02 Thread Michael Selik
Michael Selik added the comment: If you're going to tackle this problem, this should probably be solved for the general case of n <= 0 rather than just n == 0. In [1]: import random In [2]: class Random(random.Random): ...: def random(self): ...: return

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-01 Thread Wolfgang Maier
Change by Wolfgang Maier : -- keywords: +patch pull_requests: +6050 stage: -> patch review ___ Python tracker

[issue33203] random.choice: raise IndexError on empty sequence even when not using getrandbits internally

2018-04-01 Thread Wolfgang Maier
New submission from Wolfgang Maier : from https://docs.python.org/3/library/random.html#random.choice: Return a random element from the non-empty sequence seq. If seq is empty, raises IndexError. Indeed: >>> import random >>> random.choice([])