mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
fix: resolve mypy errors and update shell tool count in tests
- Fix type shadowing in forgiving_edit.py (needle_lines int/list conflict) - Add return type annotations to prompts functions - Fix change_type indexing for None case in utils.py - Fix commit.message bytes/str handling in utils.py - Add proper dict typing for tree entries in utils.py - Update shell tool count from 8 to 9 in test assertions
This commit is contained in:
@@ -16,7 +16,7 @@ Be constructive and specific in your feedback."""
|
||||
|
||||
|
||||
# You can also create dynamic prompts that take parameters
|
||||
def create_custom_analysis_prompt(file_path: str, analysis_type: str = "general"):
|
||||
def create_custom_analysis_prompt(file_path: str, analysis_type: str = "general") -> str:
|
||||
"""Create a dynamic analysis prompt for a specific file."""
|
||||
|
||||
analysis_types = {
|
||||
|
||||
@@ -584,7 +584,7 @@ Tools NOT available in batch (require state/session):
|
||||
- todo_write"""
|
||||
|
||||
|
||||
def create_tool_category_prompt(category: str, tools: list[str]):
|
||||
def create_tool_category_prompt(category: str, tools: list[str]) -> str:
|
||||
"""Create a dynamic prompt for a specific tool category."""
|
||||
|
||||
tool_descriptions = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import platform
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from git import Repo
|
||||
@@ -108,7 +109,7 @@ def get_directory_structure(
|
||||
|
||||
for entry in entries:
|
||||
if entry.is_dir():
|
||||
entry_data = {"name": entry.name, "type": "directory"}
|
||||
entry_data: dict[str, Any] = {"name": entry.name, "type": "directory"}
|
||||
|
||||
# Check if we should filter this directory
|
||||
if should_filter(entry):
|
||||
@@ -226,7 +227,8 @@ def get_git_info(path: str) -> dict[str, str | None]:
|
||||
if staged_files:
|
||||
for item in staged_files[:25]: # Limit to first 25
|
||||
change_type = item.change_type
|
||||
status_lines.append(f"{change_type[0].upper()} {item.a_path}")
|
||||
ct = str(change_type)[0].upper() if change_type else "?"
|
||||
status_lines.append(f"{ct} {item.a_path}")
|
||||
if len(staged_files) > 25:
|
||||
status_lines.append(
|
||||
f"... and {len(staged_files) - 25} more staged files"
|
||||
@@ -264,8 +266,9 @@ def get_git_info(path: str) -> dict[str, str | None]:
|
||||
commits = []
|
||||
for commit in repo.iter_commits(max_count=5):
|
||||
short_hash = commit.hexsha[:7]
|
||||
message = commit.message.split("\n")[0] # First line only
|
||||
commits.append(f"{short_hash} {message}")
|
||||
msg = commit.message
|
||||
first_line = (msg.decode() if isinstance(msg, bytes) else str(msg)).split("\n")[0]
|
||||
commits.append(f"{short_hash} {first_line}")
|
||||
recent_commits = "\n".join(commits)
|
||||
except Exception:
|
||||
recent_commits = "Unable to get recent commits"
|
||||
|
||||
@@ -80,13 +80,13 @@ class ForgivingEditHelper:
|
||||
start_pos = sum(len(line) + 1 for line in original_lines[:lines_before])
|
||||
|
||||
# Find end position by counting lines in needle
|
||||
needle_lines = norm_needle.count("\n") + 1
|
||||
needle_line_count = norm_needle.count("\n") + 1
|
||||
end_pos = sum(
|
||||
len(line) + 1 for line in original_lines[: lines_before + needle_lines]
|
||||
len(line) + 1 for line in original_lines[: lines_before + needle_line_count]
|
||||
)
|
||||
|
||||
matched = "\n".join(
|
||||
original_lines[lines_before : lines_before + needle_lines]
|
||||
original_lines[lines_before : lines_before + needle_line_count]
|
||||
)
|
||||
return (start_pos, end_pos - 1, matched)
|
||||
|
||||
@@ -97,7 +97,7 @@ class ForgivingEditHelper:
|
||||
if len(needle_lines) == 1:
|
||||
# Single line - find best match
|
||||
needle_norm = ForgivingEditHelper.normalize_whitespace(needle)
|
||||
best_ratio = 0
|
||||
best_ratio: float = 0.0
|
||||
best_match = None
|
||||
|
||||
for i, line in enumerate(haystack_lines):
|
||||
|
||||
@@ -282,7 +282,7 @@ class TestTotalToolCount:
|
||||
# Required packages with exact counts
|
||||
required_packages = [
|
||||
("hanzo_tools.fs", 1),
|
||||
("hanzo_tools.shell", 8),
|
||||
("hanzo_tools.shell", 9),
|
||||
("hanzo_tools.browser", 1),
|
||||
("hanzo_tools.memory", 1), # unified memory tool
|
||||
("hanzo_tools.todo", 1),
|
||||
|
||||
Reference in New Issue
Block a user