MutaFix run: toolz-006
ranker nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B · patcher nvidia/nemotron-3-super-120b-a12b · via Nebius Token Factory
- if not (not callable(key)): (injected bug)+ if not callable(key): (original)retriever rank 1 of 20 · ranker position 1 · patched the right function yes · exact restore no
Trace
failing tests and errors
toolz/tests/test_recipes.py::test_countbytoolz/tests/test_recipes.py::test_countby
E TypeError: 'int' object is not subscriptable
toolz/tests/test_recipes.py::test_countby in the static call graph. Kept 20 candidates, ranked by spectrum score (Ochiai), call graph and BM25 break ties.candidates in retriever order
toolz/recipes.py::countbytoolz/itertoolz.py::frequenciestoolz/__init__.py::__getattr__toolz/itertoolz.py::gettertoolz/itertoolz.py::uniquetoolz/functoolz.py::memoize.<locals>.memoftoolz/_signatures.py::signature_or_spectoolz/itertoolz.py::isiterabletoolz/functoolz.py::curry.__init__toolz/_signatures.py::check_validtoolz/itertoolz.py::groupbytoolz/functoolz.py::curry.__call__toolz/functoolz.py::fliptoolz/itertoolz.py::tailtoolz/dicttoolz.py::_get_factorytoolz/itertoolz.py::partition_alltoolz/functoolz.py::_check_sigspectoolz/functoolz.py::curry.__signature__toolz/functoolz.py::memoizetoolz/functoolz.py::is_valid_args
toolz/recipes.py::countbytoolz/itertoolz.py::frequenciestoolz/__init__.py::__getattr__toolz/itertoolz.py::gettertoolz/itertoolz.py::unique
read toolz/recipes.py::countby
The failing test calls countby with an integer (0) as the key function, but the current implementation only checks `not callable(key)` which is true for integers, causing `key` to be treated as a literal value instead of being used as a function. This leads to trying to subscript an integer later in `frequencies(map(key, seq))`, resulting in the 'int' object is not subscriptable error.
The current condition `if not (not callable(key))` is equivalent to `if callable(key)`, but it's confusing and the logic is inverted in intent. The bug occurs when a non-callable (like integer 0) is passed as `key`; the current code treats it as a function and tries to use `getter` on it, but the condition check is backwards. The fix clarifies the intent: only use `getter` when `key` is not callable, preventing the erroneous behavior with integers.
--- a/toolz/recipes.py+++ b/toolz/recipes.py@@ -19,5 +19,7 @@ groupby """- if not (not callable(key)):+ if callable(key):+ pass+ else: key = getter(key) return frequencies(map(key, seq))
tests: all tests pass
Final patch
--- a/toolz/recipes.py+++ b/toolz/recipes.py@@ -19,5 +19,7 @@ groupby """- if not (not callable(key)):+ if callable(key):+ pass+ else: key = getter(key) return frequencies(map(key, seq))