Merge pull request #1216 from akaihola/misc-cleanups

Clean up types and drop an unused variable
This commit is contained in:
paul-gauthier 2024-08-29 13:16:48 -07:00 committed by GitHub
commit 59cb457008
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 14 deletions

View file

@ -111,9 +111,9 @@ class EditBlockFunctionCoder(Coder):
updated = get_arg(edit, "updated_lines") updated = get_arg(edit, "updated_lines")
# gpt-3.5 returns lists even when instructed to return a string! # 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) 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) updated = "\n".join(updated)
if original and not original.endswith("\n"): if original and not original.endswith("\n"):

View file

@ -529,7 +529,9 @@ class Commands:
# Handle absolute paths # Handle absolute paths
raw_matched_files = [Path(pattern)] raw_matched_files = [Path(pattern)]
else: 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: except ValueError as err:
self.io.tool_error(f"Error matching {pattern}: {err}") self.io.tool_error(f"Error matching {pattern}: {err}")
raw_matched_files = [] raw_matched_files = []
@ -539,9 +541,9 @@ class Commands:
matched_files += expand_subdir(fn) matched_files += expand_subdir(fn)
matched_files = [ matched_files = [
str(Path(fn).relative_to(self.coder.root)) fn.relative_to(self.coder.root)
for fn in matched_files 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 # if repo, filter against it
@ -555,8 +557,6 @@ class Commands:
def cmd_add(self, args): def cmd_add(self, args):
"Add files to the chat so aider can edit them or review them in detail" "Add files to the chat so aider can edit them or review them in detail"
added_fnames = []
all_matched_files = set() all_matched_files = set()
filenames = parse_quoted_filenames(args) filenames = parse_quoted_filenames(args)
@ -618,7 +618,6 @@ class Commands:
self.io.tool_output( self.io.tool_output(
f"Moved {matched_file} from read-only to editable files in the chat" f"Moved {matched_file} from read-only to editable files in the chat"
) )
added_fnames.append(matched_file)
else: else:
self.io.tool_error( self.io.tool_error(
f"Cannot add {matched_file} as it's not part of the repository" f"Cannot add {matched_file} as it's not part of the repository"
@ -637,7 +636,6 @@ class Commands:
self.coder.abs_fnames.add(abs_file_path) self.coder.abs_fnames.add(abs_file_path)
self.io.tool_output(f"Added {matched_file} to the chat") self.io.tool_output(f"Added {matched_file} to the chat")
self.coder.check_added_files() self.coder.check_added_files()
added_fnames.append(matched_file)
def completions_drop(self): def completions_drop(self):
files = self.coder.get_inchat_relative_files() files = self.coder.get_inchat_relative_files()
@ -1081,7 +1079,6 @@ class Commands:
def expand_subdir(file_path): def expand_subdir(file_path):
file_path = Path(file_path)
if file_path.is_file(): if file_path.is_file():
yield file_path yield file_path
return return
@ -1089,7 +1086,7 @@ def expand_subdir(file_path):
if file_path.is_dir(): if file_path.is_dir():
for file in file_path.rglob("*"): for file in file_path.rglob("*"):
if file.is_file(): if file.is_file():
yield str(file) yield file
def parse_quoted_filenames(args): def parse_quoted_filenames(args):

View file

@ -18,7 +18,7 @@ class TestUtils(unittest.TestCase):
def test_find_filename(self): def test_find_filename(self):
fence = ("```", "```") 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 # Test with filename on a single line
lines = ["file1.py", "```"] lines = ["file1.py", "```"]
@ -45,8 +45,8 @@ class TestUtils(unittest.TestCase):
self.assertEqual(eb.find_filename(lines, fence, valid_fnames), "file1.py") self.assertEqual(eb.find_filename(lines, fence, valid_fnames), "file1.py")
# Test with fuzzy matching # Test with fuzzy matching
lines = ["\windows__init__.py", "```"] lines = [r"\windows__init__.py", "```"]
self.assertEqual(eb.find_filename(lines, fence, valid_fnames), "\windows\__init__.py") self.assertEqual(eb.find_filename(lines, fence, valid_fnames), r"\windows\__init__.py")
# fuzzy logic disabled v0.11.2-dev # fuzzy logic disabled v0.11.2-dev
def __test_replace_most_similar_chunk(self): def __test_replace_most_similar_chunk(self):