-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135647: fix random.vonmisesvariate() and random.lognormvariate() accept invalid parameters #135717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
…te() accept invalid parameters
70f524f
to
749d105
Compare
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Our past position of this was to not expend clock cycles defending against invalid inputs, leaving the user with garbage-in-garbage-out. In some cases, we have cheap checks for likely errors. In others, there is a preference for a fast code path. In this case, error checks are being added despite not having any known user issues. ISTM this PR makes everyone pay for a problem that almost no one has. Tim, @tim-one , do you want to decide this one? |
I think my position on this should be obvious, given that I'm the author of:
😄 There are cases where that's impractical, but not - to my eyes - these cases. For example, sorting implicitly requires that elements support a consistent, deterministic, total ordering. But there's no way to check for that. The sorting code nevertheless never assumes that Here For |
Just to add on, seems like other distributions also do an error check as well already. For e.g:
|
Some do, some don't. Each case has its own cost/benefit analysis, a likelihood of erroneous user input weighed against cost of the additional code. A big slow function like binomialvariate doesn't is affected much by error checks. Other functions with tighter code would feel it more. With respect to the likelihood of erroneous input, a function like lognormvariate has two and half decades of deployment indicating that the risk is near zero. Side note: Tim's position is less obvious than he claims. The issue is assigned to him and he could just commit it but hasn't. In earlier issues, he pushed for all the complexity of the |
@rhettinger, aa I said, I don't believe this PR is ready to commit. In particular, focusing on And as already explained, the idea that skipping the check in I don't recall the specifics of what else you may be talking about. For example, I did push for a major speedup in I sometimes go to extreme lengths to save cycles, and you already know (or should know) that. But rarely (not never) at the expense of letting errors pass silently. And I don't care that nobody ever complained about these specific cases. Most users apply blind trust to library functions, and if they do stumble into finding out that a library returned garbage for a bad argument, most never speak up.
That didn't stop it from being one of the most widely used PRNGs in its time, and only God knows how many bad decisions were based on its poor quality. I'm not a fan of catastrophe-driven development. I think it's our duty to pro-actively do what we can to prevent disasters. Validating input constraints is just very basic best practice. In any case, yes, I intend to merge this PR - but not before it's ready to merge. |
@rhettinger, I've tried, but I have no memory of ever talking about About |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
fix random.vonmisesvariate() and random.lognormvariate() accept invalid parameters. Throw ValueError if kappa < 0 and sigma < 0 for random.vonmisesvariate() and random.lognormvariate() respectively.