One function
windowed in more-itertools/more-itertools
The author described this change as “Issue #1057: Raise exception for invalid size in windowed()”. It counts as a record because the check below fails on the code as it stood at e4d2a4a2a and passes on 71b46b06f, with nothing else changed between the two runs.
Fix saved2026-04-01
Sharing licenceMIT · LICENSE
Change size+2 −5
What the code was meant to do, written into the code itself as a docstring
Return a sliding window of width *n* over the given iterable. When the window is larger than the iterable, *fillvalue* is used in place of missing values: Each window will advance in increments of *step*: To slide into the iterable's items, use :func:`chain` to add filler items to the left:
The change
| 25 | 25 | >>> list(windowed(chain(padding, iterable), 3)) | |
| 26 | 26 | [(None, None, 1), (None, 1, 2), (1, 2, 3), (2, 3, 4)] | |
| 27 | 27 | """ | |
| 28 | - | if n < 0: | |
| 29 | - | raise ValueError('n must be >= 0') | |
| 30 | - | if n == 0: | |
| 31 | - | yield () | |
| 32 | - | return | |
| 28 | + | if n <= 0: | |
| 29 | + | raise ValueError('n must be > 0') | |
| 33 | 30 | if step < 1: | |
| 34 | 31 | raise ValueError('step must be >= 1') | |
| 35 | 32 |
The check that tells the two apart
fail→pass·tests/test_more.py::WindowedTests::test_invalid_n
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 ite4d2a4a2a97246a73856754b2c4866d7f41d4875
Broken version dated2026-03-31
Modulemore_itertools.more
Units changedwindowed
Fingerprint2a0dd340000cf62f
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-07-03sliced
- 2026-06-30tail
- 2026-06-30interleave_evenly
- 2026-01-02nth_combination_with_replacement
- 2026-01-02nth_permutation