One function
sliced in more-itertools/more-itertools
The author described this change as “Raise for negative slice sizes in sliced()”. It counts as a record because the check below fails on the code as it stood at ed86a1528 and passes on 958990e22, with nothing else changed between the two runs.
Fix saved2026-07-03
Sharing licenceMIT · LICENSE
Change size+3 −0
What the code was meant to do, written into the code itself as a docstring
Yield slices of length *n* from the sequence *seq*. By the default, the last yielded slice will have fewer than *n* elements if the length of *seq* is not divisible by *n*: If the length of *seq* is not divisible by *n* and *strict* is `True`, then `ValueError` will be raised before the last slice is yielded. This function will only work for iterables that support slicing. For non-sliceable iterables, see :func:`chunked`.
The change
| 18 | 18 | For non-sliceable iterables, see :func:`chunked`. | |
| 19 | 19 | ||
| 20 | 20 | """ | |
| 21 | + | if n < 0: | |
| 22 | + | raise ValueError('n must be at least 0') | |
| 23 | + | ||
| 21 | 24 | iterator = takewhile(len, (seq[i : i + n] for i in count(0, n))) | |
| 22 | 25 | if strict: | |
| 23 | 26 |
The check that tells the two apart
fail→pass·tests/test_more.py::SlicedTests::test_negative
Check file tests/test_more.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before ited86a1528aa015f219f8d3385ea2ebd3f63a5212
Broken version dated2026-07-01
Modulemore_itertools.more
Units changedsliced
Fingerprint401401565252e6dd
Checked2026-08-17 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in more-itertools/more-itertools
- 2026-07-19chunked
- 2026-06-30tail
- 2026-06-30interleave_evenly
- 2026-04-01windowed
- 2026-01-02nth_combination_with_replacement
- 2026-01-02nth_permutation