MutaFix run: toolz-005
ranker nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B · patcher nvidia/nemotron-3-super-120b-a12b · via Nebius Token Factory
- if not (func not in signatures): (injected bug)+ if func not in signatures: (original)retriever rank 1 of 20 · ranker position 1 · patched the right function yes · exact restore yes
Trace
failing tests and errors
toolz/tests/test_curried.py::test_curried_namespace toolz/tests/test_inspect_args.py::test_has_keywords toolz/tests/test_signatures.py::test_for_coveragetoolz/tests/test_curried.py::test_curried_namespace
E AssertionError: partial should come from toolz and NOT be curriedtoolz/tests/test_inspect_args.py::test_has_keywords
E assert None E + where None = has_keywords(int)
toolz/tests/test_curried.py::test_curried_namespace in the static call graph. Kept 20 candidates, ranked by spectrum score (Ochiai), call graph and BM25 break ties.candidates in retriever order
toolz/_signatures.py::_has_keywordstoolz/functoolz.py::has_keywordstoolz/dicttoolz.py::valfiltertoolz/functoolz.py::curry.__eq__toolz/functoolz.py::curry.__ne__toolz/dicttoolz.py::mergetoolz/_signatures.py::_is_aritytoolz/functoolz.py::num_required_argstoolz/_signatures.py::check_aritytoolz/functoolz.py::_check_sigspectoolz/dicttoolz.py::merge_withtoolz/_signatures.py::_num_required_argstoolz/functoolz.py::is_aritytoolz/_signatures.py::check_required_argstoolz/dicttoolz.py::_get_factorytoolz/_signatures.py::_has_varargstoolz/functoolz.py::curry.__init__toolz/functoolz.py::curry.__call__toolz/functoolz.py::curry.functoolz/functoolz.py::curry.args
toolz/_signatures.py::_has_keywordstoolz/functoolz.py::has_keywordstoolz/dicttoolz.py::valfiltertoolz/functoolz.py::curry.__eq__toolz/functoolz.py::curry.__ne__
read toolz/functoolz.py::has_keywords
The test `test_has_keywords` expects `has_keywords(int)` to return `None`, but the current implementation returns `True` for functions with no keywords. The candidate `_has_keywords` in `toolz/_signatures.py` returns `None` when `any(checks)` is true, which matches the expected behavior. However, the test failure suggests a logic issue in how the result is handled. I need to examine the source of `_has_keywords` to confirm the exact logic.
read toolz/_signatures.py::_has_keywords
The test `test_has_keywords` fails because `has_keywords(int)` returns `True` instead of `None`. The root cause appears to be in `_has_keywords` (candidate 1), which returns `None` only when `all(checks)` is true, but returns `True` when `any(checks)` is true. However, the test expects `None` when there are no keywords. The logic in `_has_keywords` might be inverted. Let me read the full source of `_has_keywords` to confirm the exact behavior.
I notice the old and new code are identical, which means my proposed patch would have no effect. This indicates I misunderstood the issue. Let me re-examine the test failure. Looking at the test `test_has_keywords`: it asserts that `has_keywords(int)` should return `None`. From the traceback, we see `assert None` failed, meaning `has_keywords(int)` returned something that is not `None` (likely `False`). In `_has_keywords`, the function returns: - `None` if `func in signatures` (line 763) - Otherwise, it computes `checks = [check_keywords(sig) for sig in sigs]` - Returns `True` if all checks are true - Returns `None` if any check is true (but not all) - Returns `False` if no checks are true For `int`, which has no keyword parameters, `check_keywords(sig)` should return `False` for its signature(s). So `checks` would be a list of `False` values. Then `all(checks)` is `False`, `any(checks)` is `False`, so the function returns `False`. But the test expects `None`. This suggests that for built-in functions like `int`, we should return `None` when we cannot determine the signature definitively. Looking at line 763: `if not (func not in signatures):` which is equivalent to `if func in signatures:` then return `None`. This means if the function IS in the signatures cache, we return `None`. But for `int`, if it's NOT in signatures, we proceed to compute checks. The test expects `None` for `has_keywords(int)`, which means we want the function to return `None` when we cannot determine if it has keywords. The current logic returns `None` only when: 1. `func in signatures` (line 763), OR 2. `not all(checks) and any(checks)` (line 769-770) It returns `False` only when `not any(checks)` (line 771). So to make `has_keywords(int)` return `None`, we need either: - `int` to be in `signatures`, OR - The checks to have mixed results (some True, some False) Since `int` has a single signature with no keywords, `check_keywords` should return `False` for it, making `checks = [False]`, so `any(checks)` is `False`, and we return `False`. The problem might be that `int` should be treated as having undetermined keyword status, hence return `None`. Looking at the condition on line 763: it returns `None` if `func in signatures`. Perhaps we should return `None` when `func NOT in signatures` instead? Let me check what the function is supposed to do. The name `_has_keywords` suggests it should return: - `True` if the function definitely has keyword parameters - `False` if it definitely does not - `None` if we cannot determine Currently: - Returns `None` if `func in signatures` (opposite of what we want) - Returns `True` if all signatures have keywords - Returns `None` if some signatures have keywords - Returns `False` if no signatures have keywords This is backwards! The first condition should probably return `None` when we DON'T have signature info, not when we DO. Let me propose the fix: change line 763 from `if not (func not in signatures):` to `if func not in signatures:` so that we return `None` when signature info is missing.
tests: 3 failing (target tests)
toolz/tests/test_curried.py::test_curried_namespace toolz/tests/test_inspect_args.py::test_has_keywords toolz/tests/test_signatures.py::test_for_coverage
model reasoning (excerpt)
We have three failing tests:
1. test_curried_namespace: "partial should come from toolz and NOT be curried"
2. test_has_keywords: assert None (where None = has_keywords(int))
3. test_for_coverage: KeyError: None
Let's analyze each:
First, test_has_keywords:
The test expects has_keywords(int) to return None.
Looking at the code for has_keywords (candidate 2):
def has_keywords(func, sigspec=None):
sigspec, rv = _check_sigspec(sigspec, func, _sigs._has_keywords, func)
if sigspec is None:
return rv
... # rest
So if _check_sigspec returns sigspec=None, then we return rv (which is the result of _sigs._has_keywords(func)).
Now, what does _sigs._has_keywords (i.e., _has_keywords in toolz/_signatures.py) return for int?
Let's look at _has_keywords (candidate 1):
def _has_keywords(func):
if not (func not in signatures):
return None
sigs = signatures[func]
checks = [check_keywords(sig) for sig in sigs]
if all(checks):
return True
elif any(checks):
return None
return False
The condition at line 763: `if not (func not in signatures):` is equivalent to `if func in signatures:`.
So if func is in the signatures cache, we return None immediately? That doesn't seem right.
Actually, let's read it carefully:
if not (func not in signatures):
This is double negative: The test `test_has_keywords` expects `has_keywords(int)` to return `None`, but currently returns `False`. The root cause is in `_has_keywords`: when a function is not in the `signatures` cache (like built-in `int`), it proceeds to check its signature(s). For `int`, which has no keyword parameters, all checks are `False`, so the function returns `False`. However, when signature information is missing, we should return `None` to indicate uncertainty. The fix changes the first condition to return `None` when `func not in signatures` (i.e., when we lack signature info), which matches the expected behavior for `int`. This change should also affect the other two failing tests, as `_has_keywords` is implicated in all three.
--- a/toolz/_signatures.py+++ b/toolz/_signatures.py@@ -761,5 +761,5 @@ def _has_keywords(func):- if not (func not in signatures):+ if func not in signatures: return None sigs = signatures[func]
tests: all tests pass
model reasoning (excerpt)
We are given that the patch was reverted because it had no effect (the old and new were the same). We must have made a mistake in reading the candidate. Let me look again at the candidate: The candidate _has_keywords is: 762 | def _has_keywords(func): 763 | if not (func not in signatures): 764 | return None 765 | sigs = signatures[func] 766 | checks = [check_keywords(sig) for sig in sigs] 767 | if all(checks): 768 | return True 769 | elif any(checks): 770 | return None 771 | return False The condition on line 763: `if not (func not in signatures):` is equivalent to `if func in signatures:`. So if the function is in the signatures cache, we return None. For the test `has_keywords(int)`, we want it to return None. Currently, if `int` is in signatures, we return None (which is good). But the test fails, meaning that `has_keywords(int)` did not return None. Therefore, for `int`, the condition `func in signatures` must be false, so we went on to compute the checks. We then computed `checks = [check_keywords(sig) for sig in sigs]`. For `int`, which has no keyword parameters, each `check_keywords(sig)` should return False. So `checks` is a list of False. Then: all(checks) -> False any(checks) -> False so we return False. But we want None. So we need to change the function so that for `int` we return None. One way is to change the condition so that we return None when we don't have signature information
Final patch
--- a/toolz/_signatures.py+++ b/toolz/_signatures.py@@ -761,5 +761,5 @@ def _has_keywords(func):- if not (func not in signatures):+ if func not in signatures: return None sigs = signatures[func]