Skip to content

islice has different behavior from the standard itertools version. #22

Closed
@kbsriram

Description

@kbsriram

While writing tests for a different issue, noticed a few differences with the current islice implementation.

Some examples:

>>> import adafruit_itertools as ait
>>> import itertools as it
>>> list(it.islice("ab", 10))
['a', 'b']
>>> list(ait.islice("ab", 10))
Traceback (most recent call last):
  File "/home/kbs/venv/lib/python3.8/site-packages/adafruit_itertools/__init__.py", line 353, in islice
    yield next(it)
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: generator raised StopIteration
>>> list(it.islice("ab", -1))
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.
>>> list(ait.islice("ab", -1))
[]
>>> 

I can follow-up with a fix to more closely align the behavior, if this feels worth fixing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions