Author wyz23x2
Recipients wyz23x2
Date 2021-02-02.04:07:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1612238872.93.0.407149232495.issue43097@roundup.psfhosted.org>
In-reply-to
Content
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\random.py", 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.
History
Date User Action Args
2021-02-02 04:07:52wyz23x2setrecipients: + wyz23x2
2021-02-02 04:07:52wyz23x2setmessageid: <1612238872.93.0.407149232495.issue43097@roundup.psfhosted.org>
2021-02-02 04:07:52wyz23x2linkissue43097 messages
2021-02-02 04:07:52wyz23x2create