One function

spy in more-itertools/more-itertools

The author described this change as Fix spy to make returned iterable immutable. It counts as a record because the check below fails on the code as it stood at c0465331c and passes on 62411c161, with nothing else changed between the two runs.

Fix saved2020-03-29
Sharing licenceMIT · LICENSE
Change size+1 1

What the code was meant to do, written into the code itself as a docstring

Return a 2-tuple with a list containing the first *n* elements of *iterable*, and an iterator with the same items as *iterable*. This allows you to "look ahead" at the items in the iterable without advancing it. There is one item in the list by default: You may use unpacking to retrieve items instead of lists: The number of items requested can be larger than the number of items in the iterable:

The change

3838 it = iter(iterable)
3939 head = take(n, it)
4040
41- return head, chain(head, it)
41+ return head.copy(), chain(head, it)

The check that tells the two apart

failpass·tests/test_more.py::SpyTests::test_immutable

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 itc0465331cbc0d882cd7dce5c0bd19aaf46dfb968
Broken version dated2020-03-29
Modulemore_itertools.more
Units changedspy
Fingerprintc5b8f23c1638de5f
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