Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Fix(tools): Do not include def line; handle decorators

Kilian Lieret115195fcd340
diff --git a/tools/edit_anthropic/bin/str_replace_editor b/tools/edit_anthropic/bin/str_replace_editor
index 4a73920b..bc4dcd8b 100644
--- a/tools/edit_anthropic/bin/str_replace_editor
+++ b/tools/edit_anthropic/bin/str_replace_editor
@@ -144,11 +144,14 @@ class WindowExpander:
best_score = score
# The breakpoint is the previous line
best_breakpoint = i_line - direction
- if self.suffix == ".py" and any(re.match(r"^\s*" + keyword + r"\s+", line) for keyword in ["def", "class"]):
+ if self.suffix == ".py" and any(
+ re.match(r"^\s*" + keyword + r"\s+", line) for keyword in ["def", "class", "@"]
+ ):
+ # We include decorators here, because they are always on top of the function/class definition
score = 3
if score > best_score:
best_score = score
- best_breakpoint = i_line
+ best_breakpoint = i_line - direction
if i_line == 1 or i_line == len(lines):
score = 3
if score > best_score: