One function
chunked in more-itertools/more-itertools
The author described this change as “Raise a clear ValueError for negative n in chunked()”. It counts as a record because the check below fails on the code as it stood at 516f0a80f and passes on 0e6acdf9b, with nothing else changed between the two runs.
Fix saved2026-07-19
Sharing licenceMIT · LICENSE
Change size+3 −0
What the code was meant to do, written into the code itself as a docstring
Break *iterable* into lists of length *n*: By the default, the last yielded list will have fewer than *n* elements if the length of *iterable* is not divisible by *n*: To use a fill-in value instead, see the :func:`grouper` recipe. If the length of *iterable* is not divisible by *n* and *strict* is `True`, then `ValueError` will be raised before the last list is yielded.
The change
| 17 | 17 | list is yielded. | |
| 18 | 18 | ||
| 19 | 19 | """ | |
| 20 | + | if n is not None and n < 0: | |
| 21 | + | raise ValueError('n must be at least 0') | |
| 22 | + | ||
| 20 | 23 | iterator = iter(partial(take, n, iter(iterable)), []) | |
| 21 | 24 | if strict: | |
| 22 | 25 | if n is None: |
The check that tells the two apart
fail→pass·tests/test_more.py::ChunkedTests::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 it516f0a80fb7c2c8562dbb5e318fc2a3d44f4171f
Broken version dated2026-07-17
Modulemore_itertools.more
Units changedchunked
Fingerprint7624fd62c7397e46
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-03sliced
- 2026-06-30tail
- 2026-06-30interleave_evenly
- 2026-04-01windowed
- 2026-01-02nth_combination_with_replacement
- 2026-01-02nth_permutation