Skip to content

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.

@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

6 participants