Skip to content

Commit 44c2e38

Browse files
Fix type checking errors in MCP tests and related modules
- Fixed return type annotations in repo_operator.py methods - Added proper None handling in repo_config.py - Added try/except for SDK imports in language.py with fallback extensions - Fixed Repository import path in pr_review.py - Fixed type annotations in docs decorators - Added type ignore comments for expected TypeError tests - Reduced type checking errors from 67 to 57 diagnostics
1 parent 65440bb commit 44c2e38

File tree

7 files changed

+28
-18
lines changed

7 files changed

+28
-18
lines changed

src/codegen/git/repo_operator/repo_operator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def emptydir(self, path: str) -> None:
566566
if os.path.isfile(file_path):
567567
os.remove(file_path)
568568

569-
def get_file(self, path: str) -> str:
569+
def get_file(self, path: str) -> str | None:
570570
"""Returns the contents of a file"""
571571
file_path = self.abspath(path)
572572
try:
@@ -621,7 +621,7 @@ def get_filepaths_for_repo(self, ignore_list):
621621
decoded_filepath, _ = codecs.escape_decode(raw_filepath)
622622

623623
# Step 4: Decode those bytes as UTF-8 to get the actual Unicode text
624-
filepath = decoded_filepath.decode("utf-8")
624+
filepath = decoded_filepath.decode("utf-8") # type: ignore[union-attr]
625625

626626
# Step 5: Replace the original filepath with the decoded filepath
627627
filepaths[i] = filepath
@@ -754,7 +754,7 @@ def get_pr_data(self, pr_number: int) -> dict:
754754
"""Returns the data associated with a PR"""
755755
return self.remote_git_repo.get_pr_data(pr_number)
756756

757-
def create_pr_comment(self, pr_number: int, body: str) -> IssueComment:
757+
def create_pr_comment(self, pr_number: int, body: str) -> IssueComment | None:
758758
"""Create a general comment on a pull request.
759759
760760
Args:
@@ -765,6 +765,7 @@ def create_pr_comment(self, pr_number: int, body: str) -> IssueComment:
765765
if pr:
766766
comment = self.remote_git_repo.create_issue_comment(pr, body)
767767
return comment
768+
return None
768769

769770
def create_pr_review_comment(
770771
self,

src/codegen/git/schemas/repo_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ class RepoConfig(BaseModel):
3131
@classmethod
3232
def from_envs(cls) -> "RepoConfig":
3333
default_repo_config = RepositoryConfig()
34+
path = default_repo_config.path or os.getcwd()
35+
language = default_repo_config.language or "python"
3436
return RepoConfig(
3537
name=default_repo_config.name,
3638
full_name=default_repo_config.full_name,
37-
base_dir=os.path.dirname(default_repo_config.path),
38-
language=ProgrammingLanguage(default_repo_config.language.upper()),
39+
base_dir=os.path.dirname(path),
40+
language=ProgrammingLanguage(language.upper()),
3941
)
4042

4143
@classmethod

src/codegen/git/utils/language.py

Lines changed: 14 additions & 7 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 hardcoded 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():

src/codegen/git/utils/pr_review.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import TYPE_CHECKING
22

3-
from github import Repository
43
from github.PullRequest import PullRequest
4+
from github.Repository import Repository
55
from unidiff import PatchSet
66

77
from codegen.git.models.pull_request_context import PullRequestContext
@@ -97,7 +97,7 @@ class CodegenPR:
9797
_op: RepoOperator
9898

9999
# =====[ Computed ]=====
100-
_modified_file_ranges: dict[str, list[tuple[int, int]]] = None
100+
_modified_file_ranges: dict[str, list[tuple[int, int]]] | None = None
101101

102102
def __init__(self, op: RepoOperator, codebase: "Codebase", pr: PullRequest):
103103
self._op = op

src/codegen/shared/decorators/docs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import inspect
33
from collections.abc import Callable
44
from dataclasses import dataclass
5-
from typing import TypeVar
5+
from typing import Any, TypeVar
66

77

88
@dataclass
99
class DocumentedObject:
1010
name: str
1111
module: str
12-
object: any
12+
object: Any
1313

1414
def __lt__(self, other):
1515
return self.module < other.module

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() # Missing required token parameter # type: ignore[call-arg]
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() # No token provided # type: ignore[call-arg]
4343

4444

4545
def test_basic_initialization_variations():

0 commit comments

Comments
 (0)