mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-07 05:05:01 +00:00
style: Run linter on patch_coder.py
This commit is contained in:
parent
8cc8027b40
commit
8b9238ebc9
1 changed files with 30 additions and 26 deletions
|
@ -20,7 +20,9 @@ class Chunk:
|
||||||
orig_index: int = -1
|
orig_index: int = -1
|
||||||
del_lines: List[str] = field(default_factory=list)
|
del_lines: List[str] = field(default_factory=list)
|
||||||
ins_lines: List[str] = field(default_factory=list)
|
ins_lines: List[str] = field(default_factory=list)
|
||||||
context_before: List[str] = field(default_factory=list) # Store context for validation/application
|
context_before: List[str] = field(
|
||||||
|
default_factory=list
|
||||||
|
) # Store context for validation/application
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -158,7 +160,6 @@ class PatchCoder(Coder):
|
||||||
|
|
||||||
return edits
|
return edits
|
||||||
|
|
||||||
|
|
||||||
def apply_edits(self, edits: List[PatchAction]):
|
def apply_edits(self, edits: List[PatchAction]):
|
||||||
"""
|
"""
|
||||||
Applies the parsed PatchActions to the corresponding files.
|
Applies the parsed PatchActions to the corresponding files.
|
||||||
|
@ -180,7 +181,9 @@ class PatchCoder(Coder):
|
||||||
raise ValueError(f"ADD change for {action.path} has no content")
|
raise ValueError(f"ADD change for {action.path} has no content")
|
||||||
# Ensure parent directory exists
|
# Ensure parent directory exists
|
||||||
path_obj.parent.mkdir(parents=True, exist_ok=True)
|
path_obj.parent.mkdir(parents=True, exist_ok=True)
|
||||||
self.io.write_text(full_path, action.new_content.rstrip('\n') + '\n') # Ensure single trailing newline
|
self.io.write_text(
|
||||||
|
full_path, action.new_content.rstrip("\n") + "\n"
|
||||||
|
) # Ensure single trailing newline
|
||||||
|
|
||||||
elif action.type == ActionType.DELETE:
|
elif action.type == ActionType.DELETE:
|
||||||
if not path_obj.exists():
|
if not path_obj.exists():
|
||||||
|
@ -201,7 +204,9 @@ class PatchCoder(Coder):
|
||||||
# Apply the update logic using the parsed chunks
|
# Apply the update logic using the parsed chunks
|
||||||
new_content = self._apply_update(current_content, action.chunks, action.path)
|
new_content = self._apply_update(current_content, action.chunks, action.path)
|
||||||
|
|
||||||
target_full_path = self.abs_root_path(action.move_path) if action.move_path else full_path
|
target_full_path = (
|
||||||
|
self.abs_root_path(action.move_path) if action.move_path else full_path
|
||||||
|
)
|
||||||
target_path_obj = pathlib.Path(target_full_path)
|
target_path_obj = pathlib.Path(target_full_path)
|
||||||
|
|
||||||
# Ensure parent directory exists for target
|
# Ensure parent directory exists for target
|
||||||
|
@ -219,7 +224,6 @@ class PatchCoder(Coder):
|
||||||
# Raise a ValueError to signal failure, consistent with other coders.
|
# Raise a ValueError to signal failure, consistent with other coders.
|
||||||
raise ValueError(f"Error applying action '{action.type}' to {action.path}: {e}")
|
raise ValueError(f"Error applying action '{action.type}' to {action.path}: {e}")
|
||||||
|
|
||||||
|
|
||||||
def _apply_update(self, text: str, chunks: List[Chunk], path: str) -> str:
|
def _apply_update(self, text: str, chunks: List[Chunk], path: str) -> str:
|
||||||
"""
|
"""
|
||||||
Applies UPDATE chunks to the given text content.
|
Applies UPDATE chunks to the given text content.
|
||||||
|
@ -251,7 +255,8 @@ class PatchCoder(Coder):
|
||||||
# The current simplified parser doesn't provide enough info (like validated indices).
|
# The current simplified parser doesn't provide enough info (like validated indices).
|
||||||
# Raising NotImplementedError until a proper parser/applier is integrated.
|
# Raising NotImplementedError until a proper parser/applier is integrated.
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"_apply_update requires a robust parser and context handling, similar to apply_patch.py"
|
"_apply_update requires a robust parser and context handling, similar to"
|
||||||
|
" apply_patch.py"
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- Hypothetical logic assuming correct indices ---
|
# --- Hypothetical logic assuming correct indices ---
|
||||||
|
@ -275,7 +280,6 @@ class PatchCoder(Coder):
|
||||||
# current_orig_line_num = chunk_start_index + num_del
|
# current_orig_line_num = chunk_start_index + num_del
|
||||||
# --- End Hypothetical ---
|
# --- End Hypothetical ---
|
||||||
|
|
||||||
|
|
||||||
# Add remaining lines after the last chunk
|
# Add remaining lines after the last chunk
|
||||||
dest_lines.extend(orig_lines[current_orig_line_num:])
|
dest_lines.extend(orig_lines[current_orig_line_num:])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue