One function
product_index in more-itertools/more-itertools
The author described this change as “Fix product_index() with iterator input”. It counts as a record because the check below fails on the code as it stood at aa8c48008 and passes on cf186b5de, with nothing else changed between the two runs.
Fix saved2025-10-10
Sharing licenceMIT · LICENSE
Change size+1 −2
What the code was meant to do, written into the code itself as a docstring
Equivalent to `list(product(*args)).index(element)` The products of *args* can be ordered lexicographically. :func:`product_index` computes the first index of *element* without computing the previous products. `ValueError` will be raised if the given *element* isn't in the product of *args*.
The change
| 13 | 13 | """ | |
| 14 | 14 | elements = tuple(element) | |
| 15 | 15 | pools = tuple(map(tuple, args)) | |
| 16 | - | if len(element) != len(args): | |
| 16 | + | if len(elements) != len(pools): | |
| 17 | 17 | raise ValueError('element is not a product of args') | |
| 18 | 18 | ||
| 19 | 19 | index = 0 | |
| 20 | 20 | for elem, pool in zip(elements, pools): | |
| 21 | 21 | index = index * len(pool) + pool.index(elem) | |
| 22 | - | ||
| 23 | 22 | return index |
The check that tells the two apart
fail→pass·tests/test_more.py::ProductIndexTests::test_iterator_input
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 itaa8c480086052d4c2a64490d3214e67b7c6e674b
Broken version dated2025-10-09
Modulemore_itertools.more
Units changedproduct_index
Fingerprintd56a47ac809a80e8
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-04-01windowed
- 2026-01-02nth_combination_with_replacement