Issue 29055: random.choice on empty sequence should hide previous exception [patch] (original) (raw)

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

This patch uses raise x from None to hide the ValueError, resulting in much cleaner output.

-Tested on Python 3.7.0a0