itertools.islice incompatibility with CPython

Issue #2223 resolved
Jonas Pfannschmidt
created an issue

itertools.islice accepts floats as parameters in CPython but not in pypy.

CPython (Python 2.7):

>>> import itertools
>>> itertools.islice([1,2,3,4,5,6,7,8,9], 1.0, 6.0, 2.0)
<itertools.islice object at 0x7f14cd0d1e10>

pypy:

>>>> import itertools
>>>> itertools.islice([1,2,3,4,5,6,7,8,9], 1.0, 6.0, 2.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Indicies for islice() must be None or non-negative integers

Please note that the behaviour in CPython for Python 3 is again different:

>>> import itertools
>>> itertools.islice([1,2,3,4,5,6,7,8,9], 1.0, 6.0, 2.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize.

I sent a pull request with a fix (Python 2.7 only): https://bitbucket.org/pypy/pypy/pull-requests/386/add-support-for-floats-as-parameters-to/diff

Comments (3)

  1. Log in to comment