MutaFix run: more-itertools-006
ranker nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B · patcher nvidia/nemotron-3-super-120b-a12b · via Nebius Token Factory
- if not (not any(map(is_, start, perm))): (injected bug)+ if not any(map(is_, start, perm)): (original)retriever rank 1 of 20 · ranker position 1 · patched the right function yes · exact restore yes
Trace
failing tests and errors
tests/test_recipes.py::TestRandomDerangement::test_basicstests/test_recipes.py::TestRandomDerangement::test_basics
E AssertionError: True is not false
tests/test_recipes.py::TestRandomDerangement::test_basics 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/recipes.py::random_derangementmore_itertools/more.py::derangementsmore_itertools/more.py::subfactorialmore_itertools/more.py::set_partitionsmore_itertools/recipes.py::is_primemore_itertools/recipes.py::running_statisticsmore_itertools/recipes.py::multinomialmore_itertools/more.py::outer_productmore_itertools/recipes.py::running_meanmore_itertools/more.py::nth_primemore_itertools/more.py::samplemore_itertools/more.py::constrained_batchesmore_itertools/more.py::unique_to_eachmore_itertools/more.py::onemore_itertools/more.py::windowedmore_itertools/more.py::is_sortedmore_itertools/recipes.py::_running_median_minheap_onlymore_itertools/more.py::_islice_helpermore_itertools/more.py::gray_productmore_itertools/recipes.py::sum_of_squares
more_itertools/recipes.py::random_derangementmore_itertools/more.py::derangementsmore_itertools/more.py::subfactorialmore_itertools/more.py::set_partitionsmore_itertools/recipes.py::is_prime
read more_itertools/recipes.py::random_derangement
The failing test checks that a derangement has no fixed points (no element at its original index). The bug is likely in the condition that verifies this property. In the current implementation the condition `if not (not any(map(is_, start, perm)))` is intended to ensure that no element stays in its original position, but it is inverted: it returns True when there *is* a fixed point, causing the loop to continue only when a derangement is found. This leads to the test asserting `True is not false` which fails. The fix is to invert the condition so that the loop continues only when a fixed point is present and returns the permutation when no fixed points exist.
The condition must be true only when there are no fixed points. The double negation in the original code inverts the logic, causing the function to return a permutation that still has fixed points. Removing the outer negation makes the check correctly return True when no element is in its original position, allowing the derangement to be returned.
--- a/more_itertools/recipes.py+++ b/more_itertools/recipes.py@@ -1624,4 +1624,4 @@ while True: shuffle(perm)- if not (not any(map(is_, start, perm))):+ if not any(map(is_, start, perm)): return itemgetter(*perm)(seq)
tests: all tests pass
Final patch
--- a/more_itertools/recipes.py+++ b/more_itertools/recipes.py@@ -1624,4 +1624,4 @@ while True: shuffle(perm)- if not (not any(map(is_, start, perm))):+ if not any(map(is_, start, perm)): return itemgetter(*perm)(seq)