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

bpo-37319: Deprecated support of non-integer arguments in random.randrange(). #19112

Merged
merged 10 commits into from
Jan 25, 2021

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 22, 2020

@rhettinger
Copy link
Contributor

I don't think this should be done. It churns an API that has been stable for two decades. It doesn't solve a real problem. It may break working code. It makes the code look gross. It will complicate maintenance.

Lib/random.py Outdated Show resolved Hide resolved
@alimcmaster1
Copy link

Looks like this is good to close from the discussion on https://bugs.python.org/issue37319 ?

@serhiy-storchaka serhiy-storchaka deleted the randrange-index branch April 11, 2020 08:01
@serhiy-storchaka serhiy-storchaka restored the randrange-index branch October 31, 2020 19:33
@serhiy-storchaka
Copy link
Member Author

Reopened because @rhettinger just opened a duplicate issue.

According to the same microbenchmark as in #23064, this PR provides a 10% speed up:

$ ./python -m timeit -s 'from random import randrange' 'randrange(15)' # baseline
500000 loops, best of 5: 515 nsec per loop
$ ./python -m timeit -s 'from random import randrange' 'randrange(15)'  # new version
500000 loops, best of 5: 467 nsec per loop

except TypeError:
istep = int(step)
if istep != step:
raise ValueError("non-integer step for randrange()")
Copy link
Contributor

Choose a reason for hiding this comment

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

While we're at it, the exception type should be converted to TypeError.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we raise it with custom message or reraise the exception raised by index()?

@serhiy-storchaka
Copy link
Member Author

@rhettinger, what are your problems with this PR? I addressed your comments, and would appreciate any other suggestions.

@rhettinger
Copy link
Contributor

I merged in PR 23064. If you want to make further modifications or improvements that would be welcome.

@serhiy-storchaka
Copy link
Member Author

I merged with master. Please make review.

@serhiy-storchaka serhiy-storchaka merged commit f066bd9 into python:master Jan 25, 2021
@serhiy-storchaka serhiy-storchaka deleted the randrange-index branch January 25, 2021 21:02
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
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.

6 participants