fix: variable shadowing in log CLI, rename find_oldest_log to find_latest_log#137
fix: variable shadowing in log CLI, rename find_oldest_log to find_latest_log#137fanxing11 wants to merge 1 commit into
Conversation
…d_latest_log Two issues in aw_cli: 1. print_oldest_log() shadows the `path` parameter by reassigning it to the return value of find_oldest_log(). When no log file is found, the error message prints `None` instead of the original directory path. Fix: use a separate `logfile` variable. 2. find_oldest_log() actually returns the most recently modified log file (sorts by st_mtime ascending, takes [-1]). Renamed to find_latest_log() to match what the code does.
Greptile SummaryThis PR fixes two small bugs in
Confidence Score: 4/5Both fixes are correct and targeted; the only remaining nit is a stale return type annotation on the renamed function. The variable shadowing fix is straightforward and correct — the original directory is now preserved for the error message. The rename is accurate: the function returns the most-recently-modified file, so find_latest_log is the right name. The one loose end is that find_latest_log is still annotated -> Path despite having two code paths that return None implicitly; callers like print_latest_log already handle None correctly at runtime, so this is a type-checking gap rather than a functional bug. aw_cli/log.py — the return type annotation on find_latest_log should be Optional[Path] Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[aw logs command] --> B{module_name provided?}
B -- Yes --> C[print_latest_log\nlogdir / module_name]
B -- No --> D[Iterate sorted subdirs]
D --> E[print_latest_log\nsubdir]
C --> F[find_latest_log\npath, testing]
E --> F
F --> G{path.is_dir?}
G -- No --> H[return None]
G -- Yes --> I[Filter .log files\nby testing flag]
I --> J{logfiles empty?}
J -- Yes --> H
J -- No --> K[Sort by st_mtime\ntake last = newest]
K --> L[return logfile]
H --> M{logfile is None?}
L --> M
M -- Yes --> N[print: No logfile found in path]
M -- No --> O[print_log logfile]
Reviews (1): Last reviewed commit: "fix: correct variable shadowing in print..." | Re-trigger Greptile |
|
|
||
|
|
||
| def find_oldest_log(path: Path, testing=False) -> Path: | ||
| def find_latest_log(path: Path, testing=False) -> Path: |
There was a problem hiding this comment.
The return type annotation says
Path but the function can return None via two implicit returns (when path is not a directory or when logfiles is empty). Since the PR is already touching the function signature, this is a good moment to fix the annotation to Optional[Path].
| def find_latest_log(path: Path, testing=False) -> Path: | |
| def find_latest_log(path: Path, testing=False) -> Optional[Path]: |
Found two small issues in
aw_cli:1. Variable shadowing bug in
print_oldest_logpathgets reassigned to the return value offind_oldest_log(), so when no log is found the error message printsNoneinstead of the original directory:Fixed by using a separate
logfilevariable.2. Misleading function name
find_oldest_logsorts byst_mtimeand takes[-1]— that is the newest file, not the oldest. Renamed tofind_latest_logto match what the code actually does.