Skip to content

Commit

Permalink
Merge pull request #1216 from akaihola/misc-cleanups
Browse files Browse the repository at this point in the history
Clean up types and drop an unused variable
  • Loading branch information
paul-gauthier authored Aug 29, 2024
2 parents 8f7250e + 86600c7 commit 59cb457
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions aider/coders/editblock_func_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def _update_files(self):
updated = get_arg(edit, "updated_lines")

# gpt-3.5 returns lists even when instructed to return a string!
if self.code_format == "list" or type(original) == list:
if self.code_format == "list" or type(original) is list:
original = "\n".join(original)
if self.code_format == "list" or type(updated) == list:
if self.code_format == "list" or type(updated) is list:
updated = "\n".join(updated)

if original and not original.endswith("\n"):
Expand Down
15 changes: 6 additions & 9 deletions aider/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,9 @@ def glob_filtered_to_repo(self, pattern):
# Handle absolute paths
raw_matched_files = [Path(pattern)]
else:
raw_matched_files = list(Path(self.coder.root).glob(pattern))
raw_matched_files = list(
Path(self.coder.root).glob(pattern)
)
except ValueError as err:
self.io.tool_error(f"Error matching {pattern}: {err}")
raw_matched_files = []
Expand All @@ -539,9 +541,9 @@ def glob_filtered_to_repo(self, pattern):
matched_files += expand_subdir(fn)

matched_files = [
str(Path(fn).relative_to(self.coder.root))
fn.relative_to(self.coder.root)
for fn in matched_files
if Path(fn).is_relative_to(self.coder.root)
if fn.is_relative_to(self.coder.root)
]

# if repo, filter against it
Expand All @@ -555,8 +557,6 @@ def glob_filtered_to_repo(self, pattern):
def cmd_add(self, args):
"Add files to the chat so aider can edit them or review them in detail"

added_fnames = []

all_matched_files = set()

filenames = parse_quoted_filenames(args)
Expand Down Expand Up @@ -618,7 +618,6 @@ def cmd_add(self, args):
self.io.tool_output(
f"Moved {matched_file} from read-only to editable files in the chat"
)
added_fnames.append(matched_file)
else:
self.io.tool_error(
f"Cannot add {matched_file} as it's not part of the repository"
Expand All @@ -637,7 +636,6 @@ def cmd_add(self, args):
self.coder.abs_fnames.add(abs_file_path)
self.io.tool_output(f"Added {matched_file} to the chat")
self.coder.check_added_files()
added_fnames.append(matched_file)

def completions_drop(self):
files = self.coder.get_inchat_relative_files()
Expand Down Expand Up @@ -1081,15 +1079,14 @@ def cmd_settings(self, args):


def expand_subdir(file_path):
file_path = Path(file_path)
if file_path.is_file():
yield file_path
return

if file_path.is_dir():
for file in file_path.rglob("*"):
if file.is_file():
yield str(file)
yield file


def parse_quoted_filenames(args):
Expand Down
6 changes: 3 additions & 3 deletions tests/basic/test_editblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):

def test_find_filename(self):
fence = ("```", "```")
valid_fnames = ["file1.py", "file2.py", "dir/file3.py", "\windows\__init__.py"]
valid_fnames = ["file1.py", "file2.py", "dir/file3.py", r"\windows\__init__.py"]

# Test with filename on a single line
lines = ["file1.py", "```"]
Expand All @@ -45,8 +45,8 @@ def test_find_filename(self):
self.assertEqual(eb.find_filename(lines, fence, valid_fnames), "file1.py")

# Test with fuzzy matching
lines = ["\windows__init__.py", "```"]
self.assertEqual(eb.find_filename(lines, fence, valid_fnames), "\windows\__init__.py")
lines = [r"\windows__init__.py", "```"]
self.assertEqual(eb.find_filename(lines, fence, valid_fnames), r"\windows\__init__.py")

# fuzzy logic disabled v0.11.2-dev
def __test_replace_most_similar_chunk(self):
Expand Down

0 comments on commit 59cb457

Please sign in to comment.