EasyEdit icon indicating copy to clipboard operation
EasyEdit copied to clipboard

Passing custom requests to BaseEditor.edit raises TypeError

Open yuanwuyuan9 opened this issue 2 months ago • 1 comments

Describe the bug

Hi,

Passing custom requests to BaseEditor.edit() raises a TypeError, preventing the edit from running.

This breaks the custom-request path explicitly supported by the method: callers who prepare their own request records cannot pass them through edit(requests=...), even when those records are valid. The failure occurs before any model editing takes place.

The method reads kwargs["requests"] but leaves the key in kwargs, so edit_requests() receives requests both positionally and by keyword. Using kwargs.pop("requests") resolves the duplicate argument.

Found at commit 431d9bd. I have a one-line fix and regression tests ready to submit.

To Reproduce

Environment:

  • macOS 26.4
  • Python 3.9.6
  • EasyEdit commit: 431d9bd73db4608a4781010b687891737604c8e2
  • This isolated reproduction uses only the Python standard library and Git. No model, GPU, or third-party Python dependencies are needed.

Run the following from the repository root. It extracts the original edit() and normalize_ground_truths() functions from the affected commit and uses a stand-in for edit_requests() with an explicit requests parameter.

python3 - <<'PY'
import ast
import subprocess
import typing
from types import SimpleNamespace

commit = '431d9bd73db4608a4781010b687891737604c8e2'
namespace = dict(vars(typing))

for path, name in [
    ('easyeditor/editors/utils.py', 'normalize_ground_truths'),
    ('easyeditor/editors/editor.py', 'edit'),
]:
    source = subprocess.check_output(
        ['git', 'show', f'{commit}:{path}'], text=True
    )
    tree = ast.parse(source)
    if name == 'edit':
        tree = next(
            n for n in tree.body
            if isinstance(n, ast.ClassDef) and n.name == 'BaseEditor'
        )
    function = next(
        n for n in tree.body
        if isinstance(n, ast.FunctionDef) and n.name == name
    )
    exec(
        compile(ast.Module(body=[function], type_ignores=[]), path, 'exec'),
        namespace,
    )

class BaseEditor:
    edit = namespace['edit']

    def edit_requests(self, requests, sequential_edit=False, verbose=True, **kwargs):
        return requests

editor = BaseEditor()
editor.hparams = SimpleNamespace()
editor.edit(
    prompts='Who is the president?',
    target_new='Alice',
    requests=[{
        'prompt': 'Who is the president?',
        'target_new': 'Alice',
        'ground_truth': None,
        'locality': {},
        'portability': {},
    }],
)
PY

Output:

  File "easyeditor/editors/editor.py", line 233, in edit
    return self.edit_requests(requests, sequential_edit, verbose, test_generation=test_generation, **kwargs)
TypeError: edit_requests() got multiple values for argument 'requests'

### Expected behavior

Custom requests should be forwarded to `edit_requests()` once, without raising a `TypeError`. Other options should continue to be forwarded normally.

yuanwuyuan9 avatar Sep 28 '26 09:09 yuanwuyuan9

Thanks for reporting this issue. The proposed fix in #719 looks correct. I've asked the contributor to provide a minimal version of the PR that only contains the necessary change in editor.py, without the additional test file. We'll proceed with the fix once that update is made.

HaomingX avatar Oct 03 '26 13:10 HaomingX