MutaFix run: more-itertools-012
ranker nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B · patcher nvidia/nemotron-3-super-120b-a12b · via Nebius Token Factory
- if not (too_long is not None): (injected bug)+ if too_long is not None: (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::OnlyTests::test_custom_exception tests/test_more.py::OnlyTests::test_custom_value tests/test_more.py::OnlyTests::test_default_exception_message tests/test_more.py::OnlyTests::test_defaults tests/test_more.py::OnlyTests::test_falsy_custom_exception tests/test_more.py::OnlyTests::test_too_long_does_not_evaluate_reprtests/test_more.py::OnlyTests::test_custom_exception
E ValueError: Expected exactly one item in iterable, but got 1, 2, and perhaps more.tests/test_more.py::OnlyTests::test_custom_value
E TypeError: exceptions must derive from BaseException
tests/test_more.py::OnlyTests::test_custom_exception 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::onlymore_itertools/more.py::firstmore_itertools/more.py::onemore_itertools/more.py::strictly_nmore_itertools/more.py::iter_suppressmore_itertools/more.py::filter_exceptmore_itertools/more.py::map_exceptmore_itertools/more.py::numeric_range.__init__more_itertools/more.py::callback_iter.resultmore_itertools/more.py::numeric_range._index_nearmore_itertools/more.py::extractmore_itertools/recipes.py::groupermore_itertools/more.py::gray_productmore_itertools/more.py::distinct_permutationsmore_itertools/more.py::concurrent_teemore_itertools/more.py::zip_offsetmore_itertools/more.py::iequalsmore_itertools/more.py::locatemore_itertools/recipes.py::sliding_windowmore_itertools/more.py::substrings
more_itertools/more.py::onlymore_itertools/more.py::firstmore_itertools/more.py::onemore_itertools/more.py::strictly_nmore_itertools/more.py::iter_suppress
read more_itertools/more.py::only
The failing tests indicate issues with the `only` function's handling of the `too_long` parameter and exception raising. The source code of `only` (candidate 1) contains logic that raises a `ValueError` with a specific message format when more than one item is found, but the tests expect a `RuntimeError` (or custom exception) to be raised when `too_long` is provided. The bug likely lies in how the function handles the `too_long` parameter and raises exceptions.
The bug is in the condition checking for `too_long`. The original code uses `if not (too_long is not None)` which is equivalent to `if too_long is None`, causing the exception to be raised only when `too_long` is None. This is incorrect because the intent is to raise `too_long` when it is provided (i.e., when it is not None). The fix simplifies the condition to `if too_long is not None` to correctly raise the provided exception when `too_long` is specified.
--- a/more_itertools/more.py+++ b/more_itertools/more.py@@ -3691,5 +3691,5 @@ for first in iterator: for second in iterator:- if not (too_long is not None):+ if too_long is not None: raise too_long raise ValueError(
tests: all tests pass
Final patch
--- a/more_itertools/more.py+++ b/more_itertools/more.py@@ -3691,5 +3691,5 @@ for first in iterator: for second in iterator:- if not (too_long is not None):+ if too_long is not None: raise too_long raise ValueError(