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
rangeiter_new fails when creating a range of step 0 #72562
Comments
------------ current state ------------ An assertion in Objects/rangeobject.c might fail:
>>> type(iter(range(0)))
<class 'range_iterator'>
>>> type(iter(range(0)))(1, 1, 0)
Assertion failed: step != 0, file ..\Objects\rangeobject.c, line 895 This is caused by the lack of a check whether 'step' is zero, during the creation of a range_iterator object, in rangeiter_new. Note that during the creation of a range object, the function range_new does check that, by calling validate_step, which leads to the following behavior:
>>> range(1, 1, 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: range() arg 3 must not be zero
>>> ------------ proposed changes ------------
------------ diff ------------ ------------ tests ------------ |
I'm not able to trigger an assertion error when running the latest trunk in debug mode. I get a "valid" range_iterator object though, and using reduce gives me direct access to Error or not, this should be fixed, and your patch LGTM. Thanks! (I changed the type to 'behaviour' since I can't reproduce the assertion, but it doesn't make much of a difference) |
patch is LGTM. But there is one hidden inconsistency: >>> r = range(2**100)
>>> type(iter(r))
<class 'longrange_iterator'>
>>> type(iter(r))(1, 1, 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'longrange_iterator' instances Should we have same tp_new method for longrange_iterator? |
Good point Naoki. I think we can remove tp_new method from range_iterator in 3.7. Seems it is never used. The patch LGTM for 3.5-3.6, but the test should be marked as CPython implementation detail (@support.cpython_only). |
The diff files for 3.5 and 3.6 are attached (I only added @test.support.cpython_only, as you suggested). The diff file for 3.7 is also attached. It contains: The output of 'python_d.exe -m test -j3' for each version is also attached (they were all successful). P.S. If we remove the ability to create instances of range_iterator in 3.7, shouldn't we raise a DeprecationWarning in rangeiter_new in 3.5 and 3.6? |
Raising a DeprecationWarning in 3.6 doesn't hurt. |
rangeiter_new() was added in r55167. |
And merged in a6eb6acfe04a. |
The diff files for 3.6 and 3.7 are attached (named '*ver3.diff'). The output of 'python_d.exe -m test -j3' for each version is also attached (they were both successful). |
Thanks Oren. Patches for 3.5 and 3.7 LGTM, the patch for 3.6 should be fixed. Tests should pass with -Wa and -We. No need to attach test output. Just check that your patch doesn't add a regression. |
Alright, just added 'with test.support.check_warnings(('', DeprecationWarning)):'. That was totally my bad, of course, but anyway, ISTM that https://docs.python.org/devguide/index.html should say './python -We -m test -j3' in section 4 (Run the tests). |
New changeset ee049edc3fff by Serhiy Storchaka in branch '3.5': New changeset e486f3d30e0e by Serhiy Storchaka in branch '3.5': New changeset 06f065a59751 by Serhiy Storchaka in branch '3.6': New changeset e099583400f3 by Serhiy Storchaka in branch 'default': New changeset ce4af7593e45 by Serhiy Storchaka in branch '3.5': |
Thank you for your contribution Oren. |
Thanks for the reviews and patience :) |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: