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

2525 >>> list(windowed(chain(padding, iterable), 3))
2626 [(None, None, 1), (None, 1, 2), (1, 2, 3), (2, 3, 4)]
2727 """
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')
3330 if step < 1:
3431 raise ValueError('step must be >= 1')
3532

The check that tells the two apart

failpass·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