Skip to content
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

Simplify choice()'s interaction with the private _randbelow() method #19831

Merged
merged 4 commits into from
May 1, 2020

Conversation

rhettinger
Copy link
Contributor

The https://github.com/python/cpython/blob/2.7/Lib/random.py#L275 just let the indexing raise an IndexError. An intermediate trip through a ValueError isn't necessary.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides few typos LGTM.

rhettinger and others added 2 commits May 1, 2020 01:22
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. All other uses of _randbelow() check the argument for zero before the call.

On other hand, I would expect choice([]) raising a ValueError. IndexError is a legacy, a detail of the past implementation.

@rhettinger rhettinger merged commit 4168f1e into python:master May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants