From fc5c040b83e3f2825381133d27c94450e7227d65 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Wed, 28 Aug 2024 00:18:27 +0300 Subject: [PATCH 1/5] fix: drop unused var `added_fnames` from `cmd_add` --- aider/commands.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 466332150c5..3343d2808d6 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -555,8 +555,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) @@ -618,7 +616,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" @@ -637,7 +634,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() From e52d2da740a9a850b4194453b0b85aa305886543 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Thu, 29 Aug 2024 19:23:24 +0300 Subject: [PATCH 2/5] refactor: clarify Path/str types in `commands.py` --- aider/commands.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 3343d2808d6..217a8c30cec 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -5,6 +5,7 @@ import tempfile from collections import OrderedDict from pathlib import Path +from typing import Generator import git import pyperclip @@ -527,21 +528,23 @@ def glob_filtered_to_repo(self, pattern): try: if os.path.isabs(pattern): # Handle absolute paths - raw_matched_files = [Path(pattern)] + raw_matched_files: list[Path] = [Path(pattern)] else: - raw_matched_files = list(Path(self.coder.root).glob(pattern)) + raw_matched_files: list[Path] = list( + Path(self.coder.root).glob(pattern) + ) except ValueError as err: self.io.tool_error(f"Error matching {pattern}: {err}") - raw_matched_files = [] + raw_matched_files: list[Path] = [] - matched_files = [] + matched_files: list[Path] = [] for fn in raw_matched_files: 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 @@ -1076,8 +1079,7 @@ def cmd_settings(self, args): self.io.tool_output(settings) -def expand_subdir(file_path): - file_path = Path(file_path) +def expand_subdir(file_path: Path) -> Generator[Path, None, None]: if file_path.is_file(): yield file_path return @@ -1085,7 +1087,7 @@ def expand_subdir(file_path): 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): From 5376ae25e2aeb2517f86e30f4e545d70bcb47981 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:32:19 +0300 Subject: [PATCH 3/5] fix: use raw strings when backslashes --- tests/basic/test_editblock.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/basic/test_editblock.py b/tests/basic/test_editblock.py index 61d3c8668d0..037333b5922 100644 --- a/tests/basic/test_editblock.py +++ b/tests/basic/test_editblock.py @@ -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", "```"] @@ -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): From c9fc2efdd7bd8e67d0b0a8d73d6113a656f06d16 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:25:53 +0300 Subject: [PATCH 4/5] fix: type comparisons should use `is` --- aider/coders/editblock_func_coder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aider/coders/editblock_func_coder.py b/aider/coders/editblock_func_coder.py index 42bbb20f359..27aa53f115c 100644 --- a/aider/coders/editblock_func_coder.py +++ b/aider/coders/editblock_func_coder.py @@ -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"): From 86600c70aa54d5c7de090117e6bc88965f06a02e Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Thu, 29 Aug 2024 23:03:21 +0300 Subject: [PATCH 5/5] refactor: revert addition of type hints --- aider/commands.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 217a8c30cec..7a73f531117 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -5,7 +5,6 @@ import tempfile from collections import OrderedDict from pathlib import Path -from typing import Generator import git import pyperclip @@ -528,16 +527,16 @@ def glob_filtered_to_repo(self, pattern): try: if os.path.isabs(pattern): # Handle absolute paths - raw_matched_files: list[Path] = [Path(pattern)] + raw_matched_files = [Path(pattern)] else: - raw_matched_files: list[Path] = list( + 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: list[Path] = [] + raw_matched_files = [] - matched_files: list[Path] = [] + matched_files = [] for fn in raw_matched_files: matched_files += expand_subdir(fn) @@ -1079,7 +1078,7 @@ def cmd_settings(self, args): self.io.tool_output(settings) -def expand_subdir(file_path: Path) -> Generator[Path, None, None]: +def expand_subdir(file_path): if file_path.is_file(): yield file_path return