GeezerVison is showing github.com — bpo-42222: Modernize integer test/conversion in randrange() by rhettinger · Pull Request #23064 · python/cpython
Conversation
rhettinger
commented
Oct 31, 2020
•
edited by bedevere-bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Moves the int(x) == x test and conversion into the C code for operator.index().
Provides a 7% speed up:
$ pytime -s 'from random import randrange' 'randrange(15)' # baseline
500000 loops, best of 11: 540 nsec per loop
$ pytime -s 'from random import randrange' 'randrange(15)' # new versio
500000 loops, best of 11: 502 nsec per loop
It should become even faster when we get a zero-cost try.
It's odd that non-integers raise a ValueError. I think that should have been TypeError.
https://bugs.python.org/issue42222
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently you are on the way to #19112 (which already has tests and documentation and cover corner cases).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I merged in the relevant parts of #19112. The principal differences are:
- The TypeError won't start being emitted until the after the deprecation period.
- Improved wording for the doc entries.
- Tests focus solely on the deprecations.
- All existing behavior remains intact until after the deprecation.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
- The TypeError won't start being emitted until the after the deprecation period.
As in #19112 initially. I changed ValueError to TypeError on your request.
- Improved wording for the doc entries.
I would appreciate any suggestions to change wording.
- Tests focus solely on the deprecations.
Yes, tests in #19112 cover more cases.
- All existing behavior remains intact until after the deprecation.
As well as in #19112.
But this PR still has issues. It does not emit warning for randrange(10, 20, 1.0).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@rhettinger: Please replace # with GH- in the commit message next time. Thanks!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
tim-one
Awaiting requested review from tim-one
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|