Skip to content

Commit 1f89699

Browse files
Fix type checking issues
- Add type ignore comments for intentional test errors in Agent() constructor calls - Fix callable check for create_claude_session function - Replace LocalGitRepo method calls with direct git CLI operations in agent_detail.py - Add try/except blocks around SDK imports with fallback behavior in language.py and pr_review.py This addresses multiple type checking diagnostics including: - Missing argument errors in tests - Call non-callable errors - Unresolved attribute errors - Unresolved import errors for SDK modules
1 parent 75c5155 commit 1f89699

File tree

8 files changed

+51
-25
lines changed

8 files changed

+51
-25
lines changed

src/codegen/cli/commands/claude/config/claude_session_active_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
try:
2020
from codegen.cli.commands.claude.claude_session_api import update_claude_session_status
2121
except ImportError:
22-
update_claude_session_status = None
22+
update_claude_session_status: None = None
2323

2424

2525
def read_session_file() -> dict:

src/codegen/cli/commands/claude/config/claude_session_hook.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
from codegen.cli.commands.claude.claude_session_api import create_claude_session
2121
from codegen.cli.utils.org import resolve_org_id
2222
except ImportError:
23-
create_claude_session = None
23+
create_claude_session: None = None
24+
resolve_org_id: None = None
2425

2526

2627
def main():
@@ -64,7 +65,7 @@ def main():
6465

6566
# Create session via API if available
6667
agent_run_id = None
67-
if org_id:
68+
if org_id and create_claude_session is not None:
6869
agent_run_id = create_claude_session(session_id, org_id)
6970

7071
# Prepare session data

src/codegen/cli/commands/claude/config/claude_session_stop_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
try:
2020
from codegen.cli.commands.claude.claude_session_api import update_claude_session_status
2121
except ImportError:
22-
update_claude_session_status = None
22+
update_claude_session_status: None = None
2323

2424

2525
def read_session_file() -> dict:

src/codegen/cli/tui/agent_detail.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,23 @@ async def _pull_branch_async(self, branch_name: str, repo_clone_url: str) -> Non
227227

228228
try:
229229
current_repo = LocalGitRepo(Path.cwd())
230+
git_cli = current_repo.git_cli
230231

231232
# Add remote if it doesn't exist
232233
remote_name = "codegen-pr"
233234
try:
234-
current_repo.add_remote(remote_name, repo_clone_url)
235+
git_cli.create_remote(remote_name, repo_clone_url)
235236
except Exception:
236237
# Remote might already exist
237238
pass
238239

239240
# Fetch and checkout the branch
240-
current_repo.fetch_remote(remote_name)
241-
current_repo.checkout_branch(f"{remote_name}/{branch_name}", branch_name)
241+
git_cli.remote(remote_name).fetch()
242+
try:
243+
git_cli.git.checkout("-b", branch_name, f"{remote_name}/{branch_name}")
244+
except Exception:
245+
# Branch might already exist, just checkout
246+
git_cli.git.checkout(branch_name)
242247

243248
status_text.update(f"✅ Successfully checked out branch: {branch_name}")
244249
self.notify(f"✅ Switched to branch: {branch_name}")

src/codegen/git/utils/language.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,20 @@ def _determine_language_by_file_count(folder_path: str) -> ProgrammingLanguage:
4646
ProgrammingLanguage: The dominant programming language, or OTHER if no matching files found
4747
or if less than MIN_LANGUAGE_RATIO of files match the dominant language
4848
"""
49-
from codegen.sdk.python import PyFile
50-
from codegen.sdk.typescript.file import TSFile
51-
52-
EXTENSIONS = {
53-
ProgrammingLanguage.PYTHON: PyFile.get_extensions(),
54-
ProgrammingLanguage.TYPESCRIPT: TSFile.get_extensions(),
55-
}
49+
try:
50+
from codegen.sdk.python import PyFile
51+
from codegen.sdk.typescript.file import TSFile
52+
53+
EXTENSIONS = {
54+
ProgrammingLanguage.PYTHON: PyFile.get_extensions(),
55+
ProgrammingLanguage.TYPESCRIPT: TSFile.get_extensions(),
56+
}
57+
except ImportError:
58+
# Fallback to basic extensions if SDK modules are not available
59+
EXTENSIONS = {
60+
ProgrammingLanguage.PYTHON: [".py", ".pyx", ".pyi"],
61+
ProgrammingLanguage.TYPESCRIPT: [".ts", ".tsx", ".js", ".jsx"],
62+
}
5663

5764
folder = Path(folder_path)
5865
if not folder.exists() or not folder.is_dir():
@@ -109,14 +116,23 @@ def _determine_language_by_git_file_count(folder_path: str) -> ProgrammingLangua
109116
"""
110117
from codegen.git.repo_operator.repo_operator import RepoOperator
111118
from codegen.git.schemas.repo_config import RepoConfig
112-
from codegen.sdk.codebase.codebase_context import GLOBAL_FILE_IGNORE_LIST
113-
from codegen.sdk.python import PyFile
114-
from codegen.sdk.typescript.file import TSFile
115-
116-
EXTENSIONS = {
117-
ProgrammingLanguage.PYTHON: PyFile.get_extensions(),
118-
ProgrammingLanguage.TYPESCRIPT: TSFile.get_extensions(),
119-
}
119+
120+
try:
121+
from codegen.sdk.codebase.codebase_context import GLOBAL_FILE_IGNORE_LIST
122+
from codegen.sdk.python import PyFile
123+
from codegen.sdk.typescript.file import TSFile
124+
125+
EXTENSIONS = {
126+
ProgrammingLanguage.PYTHON: PyFile.get_extensions(),
127+
ProgrammingLanguage.TYPESCRIPT: TSFile.get_extensions(),
128+
}
129+
except ImportError:
130+
# Fallback to basic extensions and ignore list if SDK modules are not available
131+
GLOBAL_FILE_IGNORE_LIST = []
132+
EXTENSIONS = {
133+
ProgrammingLanguage.PYTHON: [".py", ".pyx", ".pyi"],
134+
ProgrammingLanguage.TYPESCRIPT: [".ts", ".tsx", ".js", ".jsx"],
135+
}
120136

121137
folder = Path(folder_path)
122138
if not folder.exists() or not folder.is_dir():

src/codegen/git/utils/pr_review.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ def is_modified(self, editable: "Editable") -> bool:
129129
@property
130130
def modified_symbols(self) -> list[str]:
131131
# Import SourceFile locally to avoid circular dependencies
132-
from codegen.sdk.core.file import SourceFile
132+
try:
133+
from codegen.sdk.core.file import SourceFile
134+
except ImportError:
135+
# If SDK is not available, return empty list
136+
return []
133137

134138
all_modified = []
135139
for file in self.modified_files:

tests/unit/codegen/agents/test_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_agent_init_requires_token(self):
7373
"""Test that Agent initialization requires a token parameter."""
7474
# This should raise a TypeError because token is a required parameter
7575
with pytest.raises(TypeError, match="missing 1 required positional argument: 'token'"):
76-
Agent() # Missing required token parameter
76+
Agent() # type: ignore[missing-argument] # Missing required token parameter
7777

7878
def test_agent_init_with_none_token(self):
7979
"""Test Agent initialization with None token."""

tests/unit/codegen/agents/test_usage_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_error_handling_no_token():
3939
with pytest.raises(TypeError, match="missing 1 required positional argument: 'token'"):
4040
from codegen.agents.agent import Agent
4141

42-
Agent() # No token provided
42+
Agent() # type: ignore[missing-argument] # No token provided
4343

4444

4545
def test_basic_initialization_variations():

0 commit comments

Comments
 (0)