MutaFix run: more-itertools-005
ranker nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B · patcher nvidia/nemotron-3-super-120b-a12b · via Nebius Token Factory
- yield p[:i] + [[e] + p[i]] + p[i + 2 :] (injected bug)+ yield p[:i] + [[e] + p[i]] + p[i + 1 :] (original)retriever rank 1 of 20 · ranker position 1 · patched the right function yes · exact restore yes
Trace
failing tests and errors
tests/test_more.py::SetPartitionsTests::test_each_correct tests/test_more.py::SetPartitionsTests::test_found_all tests/test_more.py::SetPartitionsTests::test_max_size tests/test_more.py::SetPartitionsTests::test_min_size tests/test_more.py::SetPartitionsTests::test_stirling_numberstests/test_more.py::SetPartitionsTests::test_each_correct
E AssertionError: Items in the first set but not the second: E 2 E 3 E 4 E 5tests/test_more.py::SetPartitionsTests::test_found_all
E AssertionError: Froze[26 chars]([0, 4], FrozenSet([1, 2], FrozenSet([3]], Fro[1503 chars][0]]] != Froze[26 chars]([0, 1], FrozenSet([3, 4]], FrozenSet([FrozenS[960 chars][0]]]
tests/test_more.py::SetPartitionsTests::test_each_correct in the static call graph. Kept 20 candidates, ranked by spectrum score (Ochiai), call graph and BM25 break ties.candidates in retriever order
more_itertools/more.py::set_partitions.<locals>.set_partitions_helpermore_itertools/more.py::set_partitionsmore_itertools/recipes.py::all_equalmore_itertools/more.py::onlymore_itertools/more.py::distinct_permutationsmore_itertools/more.py::mark_endsmore_itertools/more.py::onemore_itertools/more.py::windowed_completemore_itertools/more.py::all_uniquemore_itertools/more.py::is_sortedmore_itertools/more.py::iequalsmore_itertools/more.py::substrings_indexesmore_itertools/more.py::substringsmore_itertools/more.py::partitionsmore_itertools/more.py::spymore_itertools/more.py::unzipmore_itertools/more.py::make_decoratormore_itertools/more.py::classify_uniquemore_itertools/more.py::numeric_range._index_nearmore_itertools/recipes.py::partition
more_itertools/more.py::set_partitions.<locals>.set_partitions_helpermore_itertools/more.py::set_partitionsmore_itertools/recipes.py::all_equalmore_itertools/more.py::onlymore_itertools/more.py::distinct_permutations
read more_itertools/more.py::set_partitions.<locals>.set_partitions_helper
The failing tests show that set_partitions is producing incorrect partitions. The helper function set_partitions_helper (candidate 1) is responsible for generating partitions recursively. The bug is likely in how it constructs new partitions when adding an element to existing partitions. Specifically, line 3600 uses `p[i + 2 :]` which incorrectly skips an element when slicing the partition list. This would cause elements to be misplaced or omitted in the generated partitions, leading to the assertion failures seen in the tests.
The bug is in line 3600 of the set_partitions_helper function. When adding the element `e` to each existing partition `p`, the code incorrectly slices the list using `p[i + 2:]` which skips one element ahead, causing elements to be omitted from the resulting partition. This leads to incorrect set partitions being generated, which explains the assertion failures in the tests. The correct slice should be `p[i + 1:]` to properly include all remaining elements after inserting the new partition containing `e` at position `i`.
--- a/more_itertools/more.py+++ b/more_itertools/more.py@@ -3598,5 +3598,5 @@ for p in set_partitions_helper(M, k): for i in range(len(p)):- yield p[:i] + [[e] + p[i]] + p[i + 2 :]+ yield p[:i] + [[e] + p[i]] + p[i + 1 :] if k is None:
tests: all tests pass
Final patch
--- a/more_itertools/more.py+++ b/more_itertools/more.py@@ -3598,5 +3598,5 @@ for p in set_partitions_helper(M, k): for i in range(len(p)):- yield p[:i] + [[e] + p[i]] + p[i + 2 :]+ yield p[:i] + [[e] + p[i]] + p[i + 1 :] if k is None: