mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 08:14:59 +00:00
style: Apply linter to patch_flex_coder.py
This commit is contained in:
parent
152b8912ae
commit
134a2d60fe
1 changed files with 28 additions and 20 deletions
|
@ -252,11 +252,11 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
|
||||
def _parse_patch_text(
|
||||
self, lines: List[str], start_index: int, known_files: set[str]
|
||||
) -> List[Tuple[Optional[str], ParsedEdit]]: # Return type changed
|
||||
) -> List[Tuple[Optional[str], ParsedEdit]]: # Return type changed
|
||||
"""
|
||||
Parses patch content lines into a list of ParsedEdit objects.
|
||||
"""
|
||||
parsed_edits: List[Tuple[Optional[str], ParsedEdit]] = [] # List type changed
|
||||
parsed_edits: List[Tuple[Optional[str], ParsedEdit]] = [] # List type changed
|
||||
index = start_index
|
||||
current_file_path = None
|
||||
current_move_path = None
|
||||
|
@ -304,7 +304,10 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
self.io.tool_warning(f"Delete File target '{path}' not found in chat context.")
|
||||
|
||||
parsed_edits.append(
|
||||
(path, ParsedEdit(path=path, type=ActionType.DELETE, patch_line_num=line_num)) # Wrap in tuple
|
||||
(
|
||||
path,
|
||||
ParsedEdit(path=path, type=ActionType.DELETE, patch_line_num=line_num),
|
||||
) # Wrap in tuple
|
||||
)
|
||||
current_file_path = None # Reset current file context
|
||||
current_move_path = None
|
||||
|
@ -322,7 +325,7 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
action, index = self._parse_add_file_content(lines, index)
|
||||
action.path = path
|
||||
action.patch_line_num = line_num
|
||||
parsed_edits.append((path, action)) # Wrap in tuple
|
||||
parsed_edits.append((path, action)) # Wrap in tuple
|
||||
current_file_path = None # Reset current file context
|
||||
current_move_path = None
|
||||
continue
|
||||
|
@ -375,15 +378,17 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
replace_text += "\n"
|
||||
|
||||
parsed_edits.append(
|
||||
(current_file_path, # Add path to tuple
|
||||
ParsedEdit(
|
||||
path=current_file_path,
|
||||
type=ActionType.UPDATE,
|
||||
search_text=search_text,
|
||||
replace_text=replace_text,
|
||||
move_path=current_move_path, # Carry over move path for this hunk
|
||||
patch_line_num=hunk_start_index + 1,
|
||||
))
|
||||
(
|
||||
current_file_path, # Add path to tuple
|
||||
ParsedEdit(
|
||||
path=current_file_path,
|
||||
type=ActionType.UPDATE,
|
||||
search_text=search_text,
|
||||
replace_text=replace_text,
|
||||
move_path=current_move_path, # Carry over move path for this hunk
|
||||
patch_line_num=hunk_start_index + 1,
|
||||
),
|
||||
)
|
||||
)
|
||||
index = next_index
|
||||
continue
|
||||
|
@ -437,7 +442,7 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
)
|
||||
return action, index
|
||||
|
||||
def apply_edits(self, edits: List[Tuple[Optional[str], ParsedEdit]]): # Argument type changed
|
||||
def apply_edits(self, edits: List[Tuple[Optional[str], ParsedEdit]]): # Argument type changed
|
||||
"""
|
||||
Applies the parsed edits. Uses flexible search-and-replace for UPDATEs.
|
||||
"""
|
||||
|
@ -446,10 +451,10 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
return
|
||||
|
||||
# Group edits by file path to process them sequentially
|
||||
edits_by_path = itertools.groupby(edits, key=lambda edit: edit[0]) # Group by path in tuple
|
||||
edits_by_path = itertools.groupby(edits, key=lambda edit: edit[0]) # Group by path in tuple
|
||||
|
||||
for path, path_edits_iter in edits_by_path:
|
||||
path_edits = list(path_edits_iter) # path_edits is now a list of tuples
|
||||
path_edits = list(path_edits_iter) # path_edits is now a list of tuples
|
||||
full_path = self.abs_root_path(path)
|
||||
path_obj = pathlib.Path(full_path)
|
||||
current_content = None
|
||||
|
@ -457,8 +462,11 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
final_move_path = None # Track the last move destination for this file
|
||||
|
||||
# Check for simple ADD/DELETE first (should ideally be only one per file)
|
||||
if len(path_edits) == 1 and path_edits[0][1].type in [ActionType.ADD, ActionType.DELETE]:
|
||||
_path, edit = path_edits[0] # Unpack tuple
|
||||
if len(path_edits) == 1 and path_edits[0][1].type in [
|
||||
ActionType.ADD,
|
||||
ActionType.DELETE,
|
||||
]:
|
||||
_path, edit = path_edits[0] # Unpack tuple
|
||||
try:
|
||||
if edit.type == ActionType.ADD:
|
||||
if path_obj.exists():
|
||||
|
@ -502,8 +510,8 @@ class PatchFlexCoder(Coder): # Rename class
|
|||
if current_content is None:
|
||||
raise DiffError(f"Could not read file for UPDATE: {path}")
|
||||
|
||||
for i, item in enumerate(path_edits): # Iterate through items (tuples)
|
||||
_path, edit = item # Unpack tuple
|
||||
for i, item in enumerate(path_edits): # Iterate through items (tuples)
|
||||
_path, edit = item # Unpack tuple
|
||||
if edit.type != ActionType.UPDATE:
|
||||
raise DiffError(
|
||||
f"Unexpected action type '{edit.type}' mixed with UPDATE for {path}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue