[New-bugs-announce] [issue29055] random.choice on empty sequence should hide previous exception [patch]
then0rTh
report at bugs.python.org
Fri Dec 23 10:56:58 EST 2016
New submission from then0rTh:
Passing empty sequence to random.choice function leads to:
Traceback (most recent call last):
...
ValueError: number of bits must be greater than zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
IndexError: Cannot choose from an empty sequence
* the ValueError doesn't add any useful information, only bloats stderr
* the "During handling" line indicates that something went wrong inside random.py
This patch uses `raise x from None` to hide the ValueError, resulting in much cleaner output.
-Tested on Python 3.7.0a0
----------
components: Library (Lib)
files: random_choice_errmsg.patch
keywords: patch
messages: 283884
nosy: mark.dickinson, rhettinger, then0rTh
priority: normal
severity: normal
status: open
title: random.choice on empty sequence should hide previous exception [patch]
type: behavior
versions: Python 3.7
Added file: http://bugs.python.org/file46007/random_choice_errmsg.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29055>
_______________________________________
More information about the New-bugs-announce
mailing list