Skip to content

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