This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wyz23x2
Recipients wyz23x2
Date 2021-02-02.04:07:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
When you apply `random.choice` on empty sequences:
>>> import random
>>> random.choice([])
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
    return seq[self._randbelow(len(seq))]
IndexError: list index out of range
This message doesn't clearly state the real problem -- an empty seq.
Meanwhile, many other methods give messages.
>>> [].pop()
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
IndexError: pop from empty list
>>> import collections
>>> collections.deque().popleft()
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
IndexError: pop from an empty deque
>>> random.randrange(0, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python39\lib\", line 316, in randrange
    raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0, 0, 0)

P.S. Both are empty sequences/ranges, randrange() raises ValueError, while choice() raises IndexError.
Date User Action Args
2021-02-02 04:07:52wyz23x2setrecipients: + wyz23x2
2021-02-02 04:07:52wyz23x2setmessageid: <>
2021-02-02 04:07:52wyz23x2linkissue43097 messages
2021-02-02 04:07:52wyz23x2create