This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Oren Milman
Recipients Oren Milman
Date 2016-10-06.12:00:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
------------ 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 ------------
    1. In Objects/rangeobject.c in rangeiter_new:
        - in case 'step' is zero, raise a ValueError
        - in error messages, replace 'rangeiter' with 'range_iterator', as the latter is the name of the type in Python code

    2. In Lib/test/, add tests for calling the range_iterator type (i.e. creating a range_iterator object)

------------ diff ------------
The proposed patches diff file is attached.

------------ tests ------------
I ran 'python_d.exe -m test -j3' (on my 64-bit Windows 10) with and without the patches, and got quite the same output. (That also means my new tests in test_range passed.)
The outputs of both runs are attached.
Date User Action Args
2016-10-06 12:00:29Oren Milmansetrecipients: + Oren Milman
2016-10-06 12:00:27Oren Milmansetmessageid: <>
2016-10-06 12:00:27Oren Milmanlinkissue28376 messages
2016-10-06 12:00:27Oren Milmancreate