feat: Complete type safety improvements for CLI and service layers
Implement comprehensive type annotations and mypy configuration as part of code quality initiative. Achieve 100% type annotation coverage for main CLI entry points and resolve Optional type inconsistencies. ## Key Improvements ### CLI Layer (100% Type Coverage) - tddai_cli.py: Complete type annotations for all 21 functions - cli/core.py: Full type coverage for CLI framework (20 functions) - cli/commands/issues.py: Fixed Optional[List[str]] parameter types - cli/commands/workspace.py: Improved type checker logic for Optional handling ### Service Layer Type Safety - services/issue_service.py: Fixed Optional parameter type signatures - services/project_service.py: Updated Optional type annotations - tddai/issue_creator.py: Proper Optional[List[str]] usage - tddai/project_manager.py: Fixed Optional parameter handling ### Mypy Configuration - pyproject.toml: Added comprehensive mypy configuration - Gradual adoption strategy with module-specific strictness - Python 3.12 compatibility for proper type checking - Incremental typing approach for legacy modules ## Technical Details - Proper Optional vs Union type usage throughout - Generic type annotations for collections - Return type annotations for all public functions - Fixed implicit Optional violations (PEP 484) - Type checker logic improvements for better safety ## Benefits - Improved IDE autocomplete and error detection - Compile-time type checking for CLI commands - Better maintainability and debugging capabilities - Foundation for expanding type safety to remaining modules Resolves #27 - Type safety improvements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Issue CLI commands.
|
||||
"""
|
||||
|
||||
from typing import List
|
||||
from typing import List, Optional, Any
|
||||
|
||||
from tddai import TddaiError
|
||||
from services import IssueService
|
||||
@@ -12,7 +12,7 @@ from cli.presenters import OutputFormatter, IssueView
|
||||
class IssueCommands:
|
||||
"""Commands for issue operations."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.service = IssueService()
|
||||
|
||||
def list_issues(self) -> None:
|
||||
@@ -53,8 +53,8 @@ class IssueCommands:
|
||||
|
||||
def create_enhancement_issue(self, title: str, use_case: str,
|
||||
technical_requirements: str = "",
|
||||
acceptance_criteria: List[str] = None,
|
||||
dependencies: List[str] = None,
|
||||
acceptance_criteria: Optional[List[str]] = None,
|
||||
dependencies: Optional[List[str]] = None,
|
||||
priority: str = "Medium") -> None:
|
||||
"""Create a structured enhancement issue."""
|
||||
try:
|
||||
@@ -82,7 +82,7 @@ class IssueCommands:
|
||||
except TddaiError as e:
|
||||
OutputFormatter.exit_with_error(f"Error creating enhancement issue: {e}")
|
||||
|
||||
def create_from_template(self, template_file: str, **kwargs) -> None:
|
||||
def create_from_template(self, template_file: str, **kwargs: Any) -> None:
|
||||
"""Create issue from template file."""
|
||||
try:
|
||||
OutputFormatter.info(f"Creating issue from template: {template_file}")
|
||||
|
||||
@@ -47,6 +47,7 @@ class WorkspaceCommands:
|
||||
OutputFormatter.error("No active issue workspace")
|
||||
print(" Nothing to finish")
|
||||
OutputFormatter.exit_with_error("", 1)
|
||||
return # Explicit return for type checker
|
||||
|
||||
# Get test count before finishing
|
||||
summary = self.service.get_workspace_summary()
|
||||
|
||||
41
cli/core.py
41
cli/core.py
@@ -4,75 +4,76 @@ CLI framework core.
|
||||
Provides the main CLI framework and command delegation.
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
from .commands import WorkspaceCommands, IssueCommands, ProjectCommands, ExportCommands
|
||||
|
||||
|
||||
class CLIFramework:
|
||||
"""Main CLI framework that delegates to command classes."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.workspace = WorkspaceCommands()
|
||||
self.issues = IssueCommands()
|
||||
self.project = ProjectCommands()
|
||||
self.export = ExportCommands()
|
||||
|
||||
# Workspace operations
|
||||
def workspace_status(self):
|
||||
def workspace_status(self) -> None:
|
||||
return self.workspace.status()
|
||||
|
||||
def start_issue(self, issue_number: int):
|
||||
def start_issue(self, issue_number: int) -> None:
|
||||
return self.workspace.start_issue(issue_number)
|
||||
|
||||
def finish_issue(self):
|
||||
def finish_issue(self) -> None:
|
||||
return self.workspace.finish_issue()
|
||||
|
||||
def add_test_guidance(self):
|
||||
def add_test_guidance(self) -> None:
|
||||
return self.workspace.add_test_guidance()
|
||||
|
||||
# Issue operations
|
||||
def list_issues(self):
|
||||
def list_issues(self) -> None:
|
||||
return self.issues.list_issues()
|
||||
|
||||
def list_open_issues(self):
|
||||
def list_open_issues(self) -> None:
|
||||
return self.issues.list_open_issues()
|
||||
|
||||
def show_issue(self, issue_number: int):
|
||||
def show_issue(self, issue_number: int) -> None:
|
||||
return self.issues.show_issue(issue_number)
|
||||
|
||||
def create_issue(self, title: str, body: str, issue_type: str = "enhancement"):
|
||||
def create_issue(self, title: str, body: str, issue_type: str = "enhancement") -> None:
|
||||
return self.issues.create_issue(title, body, issue_type)
|
||||
|
||||
def create_enhancement_issue(self, title: str, use_case: str, **kwargs):
|
||||
def create_enhancement_issue(self, title: str, use_case: str, **kwargs: Any) -> None:
|
||||
return self.issues.create_enhancement_issue(title, use_case, **kwargs)
|
||||
|
||||
def create_from_template(self, template_file: str, **kwargs):
|
||||
def create_from_template(self, template_file: str, **kwargs: Any) -> None:
|
||||
return self.issues.create_from_template(template_file, **kwargs)
|
||||
|
||||
def analyze_coverage(self, issue_number: int):
|
||||
def analyze_coverage(self, issue_number: int) -> None:
|
||||
return self.issues.analyze_coverage(issue_number)
|
||||
|
||||
# Project management operations
|
||||
def setup_project_management(self):
|
||||
def setup_project_management(self) -> None:
|
||||
return self.project.setup_project_management()
|
||||
|
||||
def move_issue_to_state(self, issue_number: int, state: str):
|
||||
def move_issue_to_state(self, issue_number: int, state: str) -> None:
|
||||
return self.project.move_issue_to_state(issue_number, state)
|
||||
|
||||
def set_issue_priority(self, issue_number: int, priority: str):
|
||||
def set_issue_priority(self, issue_number: int, priority: str) -> None:
|
||||
return self.project.set_issue_priority(issue_number, priority)
|
||||
|
||||
def create_milestone(self, title: str, description: str = ""):
|
||||
def create_milestone(self, title: str, description: str = "") -> None:
|
||||
return self.project.create_milestone(title, description)
|
||||
|
||||
def list_milestones(self):
|
||||
def list_milestones(self) -> None:
|
||||
return self.project.list_milestones()
|
||||
|
||||
def assign_issue_to_milestone(self, issue_number: int, milestone_id: int):
|
||||
def assign_issue_to_milestone(self, issue_number: int, milestone_id: int) -> None:
|
||||
return self.project.assign_issue_to_milestone(issue_number, milestone_id)
|
||||
|
||||
def project_overview(self):
|
||||
def project_overview(self) -> None:
|
||||
return self.project.project_overview()
|
||||
|
||||
# Export operations
|
||||
def issue_index(self, **kwargs):
|
||||
def issue_index(self, **kwargs: Any) -> None:
|
||||
return self.export.issue_index(**kwargs)
|
||||
Reference in New Issue
Block a user