[issue41773] Clarify handling of infinity and nan in random.choices

Raymond Hettinger report at bugs.python.org
Sun Sep 13 06:08:29 EDT 2020


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

>  A user reading that error message could understand that it's 
> okay for weights to be negative as long as the total isn't, 
> which as far as I understand isn't true.

This seems like another made up issue.  One could also argue the opposite case that if the error message were changed, a user could reasonably assume that the function was in fact checking all the weights individually (which it isn't).

The docs already state that the function assumes non-negative inputs, which is in fact what it does.  The function already has reasonable error reporting for common missteps.  Also, it behaves gracefully if someone is nudging weights up and down in a way that goes slightly negative due to rounding.  Beyond that, we're hitting the limits of what it can or should do when fed garbage inputs for ill-posed problems.

It's time for this one die now.  It's already eaten an hour of my development time explaining how infinities and nans flow through functions and explaining what the Python norms are for letting them flow through versus treating them as errors.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41773>
_______________________________________


More information about the Python-bugs-list mailing list