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-39200: Correct the error message for range() empty constructor #17813

Merged
merged 4 commits into from Jan 5, 2020

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Jan 3, 2020

Copy link
Member

@corona10 corona10 left a comment

For me, this is more correct :)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Would be nice to add tests.

Objects/rangeobject.c Outdated Show resolved Hide resolved
@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jan 3, 2020

Other option - just use PyArg_UnpackTuple(args, "range", 1, 3, &start, &stop, &step) and check if stop == NULL.

@pablogsal
Copy link
Member Author

pablogsal commented Jan 3, 2020

Other option - just use PyArg_UnpackTuple(args, "range", 1, 3, &start, &stop, &step) and check if stop == NULL.

I have implemented the switch statement as we would need to do the dance with step and start anyway and I find the switch statement a bit more clear.

@pablogsal
Copy link
Member Author

pablogsal commented Jan 3, 2020

Would be nice to add tests.

Done in eb9e784

@pablogsal pablogsal force-pushed the bpo-39200 branch 2 times, most recently from e73eab4 to eb9e784 Compare Jan 3, 2020
@pablogsal
Copy link
Member Author

pablogsal commented Jan 3, 2020

Btw, as a bonus the constructor of range is anecdotally faster:

master

./python.exe -m pyperf timeit "range(1,3,4)"
.....................
Mean +- std dev: 893 ns +- 44 ns

patched

./python.exe -m pyperf timeit "range(1,3,4)"
.....................
Mean +- std dev: 822 ns +- 14 ns

Copy link
Member

@corona10 corona10 left a comment

@pablogsal I left comments on test code :)

Lib/test/test_range.py Outdated Show resolved Hide resolved
Lib/test/test_range.py Outdated Show resolved Hide resolved
Objects/rangeobject.c Outdated Show resolved Hide resolved
Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_range.py Outdated Show resolved Hide resolved
Lib/test/test_range.py Outdated Show resolved Hide resolved
Objects/rangeobject.c Outdated Show resolved Hide resolved
Objects/rangeobject.c Outdated Show resolved Hide resolved
Objects/rangeobject.c Outdated Show resolved Hide resolved
@pablogsal pablogsal merged commit 4b66fa6 into python:master Jan 5, 2020
@pablogsal pablogsal deleted the bpo-39200 branch Jan 5, 2020
@miss-islington
Copy link
Contributor

miss-islington commented Jan 10, 2020

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 10, 2020
…ythonGH-17813)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 4b66fa6)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
@bedevere-bot
Copy link

bedevere-bot commented Jan 10, 2020

GH-17940 is a backport of this pull request to the 3.8 branch.

@miss-islington
Copy link
Contributor

miss-islington commented Jan 10, 2020

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 10, 2020
…ythonGH-17813)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 4b66fa6)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
@bedevere-bot
Copy link

bedevere-bot commented Jan 10, 2020

GH-17942 is a backport of this pull request to the 3.7 branch.

shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants