Skip to content

Commit

Permalink
refactor: clarify Path/str types in commands.py
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Aug 29, 2024
1 parent fc5c040 commit e52d2da
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions aider/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tempfile
from collections import OrderedDict
from pathlib import Path
from typing import Generator

import git
import pyperclip
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1076,16 +1079,15 @@ 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

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

0 comments on commit e52d2da

Please sign in to comment.