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:
45
tddai_cli.py
45
tddai_cli.py
@@ -9,6 +9,7 @@ Business logic is handled by services, presentation by CLI framework.
|
||||
import sys
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from typing import Optional, Any
|
||||
|
||||
# Add current directory to path so we can import modules
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
@@ -16,9 +17,9 @@ sys.path.insert(0, str(Path(__file__).parent))
|
||||
from cli import CLIFramework
|
||||
|
||||
# Lazy initialization of CLI framework
|
||||
_cli_framework = None
|
||||
_cli_framework: Optional[CLIFramework] = None
|
||||
|
||||
def _get_cli():
|
||||
def _get_cli() -> CLIFramework:
|
||||
"""Get CLI framework instance (lazy initialization)."""
|
||||
global _cli_framework
|
||||
if _cli_framework is None:
|
||||
@@ -26,49 +27,49 @@ def _get_cli():
|
||||
return _cli_framework
|
||||
|
||||
|
||||
def workspace_status():
|
||||
def workspace_status() -> None:
|
||||
"""Show current workspace status."""
|
||||
_get_cli().workspace_status()
|
||||
|
||||
|
||||
def start_issue(issue_number: int):
|
||||
def start_issue(issue_number: int) -> None:
|
||||
"""Start working on an issue."""
|
||||
_get_cli().start_issue(issue_number)
|
||||
|
||||
|
||||
def finish_issue():
|
||||
def finish_issue() -> None:
|
||||
"""Finish current issue workspace."""
|
||||
_get_cli().finish_issue()
|
||||
|
||||
|
||||
def add_test_guidance():
|
||||
def add_test_guidance() -> None:
|
||||
"""Show guidance for adding tests."""
|
||||
_get_cli().add_test_guidance()
|
||||
|
||||
|
||||
def list_issues():
|
||||
def list_issues() -> None:
|
||||
"""List all issues."""
|
||||
_get_cli().list_issues()
|
||||
|
||||
|
||||
def list_open_issues():
|
||||
def list_open_issues() -> None:
|
||||
"""List only open issues."""
|
||||
_get_cli().list_open_issues()
|
||||
|
||||
|
||||
def show_issue(issue_number: int):
|
||||
def show_issue(issue_number: int) -> None:
|
||||
"""Show detailed issue information."""
|
||||
_get_cli().show_issue(issue_number)
|
||||
|
||||
|
||||
def create_issue(title: str, body: str, issue_type: str = "enhancement"):
|
||||
def create_issue(title: str, body: str, issue_type: str = "enhancement") -> None:
|
||||
"""Create a new issue."""
|
||||
_get_cli().create_issue(title, body, issue_type)
|
||||
|
||||
|
||||
def create_enhancement_issue(title: str, use_case: str, technical_requirements: str = "",
|
||||
acceptance_criteria: str = "", dependencies: str = "",
|
||||
priority: str = "Medium"):
|
||||
priority: str = "Medium") -> None:
|
||||
"""Create a structured enhancement issue."""
|
||||
# Parse acceptance criteria if provided
|
||||
criteria_list = []
|
||||
@@ -90,52 +91,52 @@ def create_enhancement_issue(title: str, use_case: str, technical_requirements:
|
||||
)
|
||||
|
||||
|
||||
def create_from_template(template_file: str, **kwargs):
|
||||
def create_from_template(template_file: str, **kwargs: Any) -> None:
|
||||
"""Create issue from template file."""
|
||||
_get_cli().create_from_template(template_file, **kwargs)
|
||||
|
||||
|
||||
def analyze_coverage(issue_number: int):
|
||||
def analyze_coverage(issue_number: int) -> None:
|
||||
"""Analyze test coverage for a specific issue."""
|
||||
_get_cli().analyze_coverage(issue_number)
|
||||
|
||||
|
||||
def setup_project_management():
|
||||
def setup_project_management() -> None:
|
||||
"""Setup project management labels and milestones."""
|
||||
_get_cli().setup_project_management()
|
||||
|
||||
|
||||
def move_issue_to_state(issue_number: int, state: str):
|
||||
def move_issue_to_state(issue_number: int, state: str) -> None:
|
||||
"""Move issue to a specific project state."""
|
||||
_get_cli().move_issue_to_state(issue_number, state)
|
||||
|
||||
|
||||
def set_issue_priority(issue_number: int, priority: str):
|
||||
def set_issue_priority(issue_number: int, priority: str) -> None:
|
||||
"""Set issue priority."""
|
||||
_get_cli().set_issue_priority(issue_number, priority)
|
||||
|
||||
|
||||
def create_milestone(title: str, description: str = ""):
|
||||
def create_milestone(title: str, description: str = "") -> None:
|
||||
"""Create a new milestone (project)."""
|
||||
_get_cli().create_milestone(title, description)
|
||||
|
||||
|
||||
def list_milestones():
|
||||
def list_milestones() -> None:
|
||||
"""List all milestones."""
|
||||
_get_cli().list_milestones()
|
||||
|
||||
|
||||
def assign_issue_to_milestone(issue_number: int, milestone_id: int):
|
||||
def assign_issue_to_milestone(issue_number: int, milestone_id: int) -> None:
|
||||
"""Assign issue to a milestone."""
|
||||
_get_cli().assign_issue_to_milestone(issue_number, milestone_id)
|
||||
|
||||
|
||||
def project_overview():
|
||||
def project_overview() -> None:
|
||||
"""Show project management overview."""
|
||||
_get_cli().project_overview()
|
||||
|
||||
|
||||
def issue_index(format_type="tsv", sort_by="number", filter_state=None, filter_priority=None, include_state=False):
|
||||
def issue_index(format_type: str = "tsv", sort_by: str = "number", filter_state: Optional[str] = None, filter_priority: Optional[str] = None, include_state: bool = False) -> None:
|
||||
"""Output compact index of all issues for Unix processing."""
|
||||
_get_cli().issue_index(
|
||||
format_type=format_type,
|
||||
@@ -146,7 +147,7 @@ def issue_index(format_type="tsv", sort_by="number", filter_state=None, filter_p
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
"""Main CLI entry point."""
|
||||
parser = argparse.ArgumentParser(description="tddai CLI tool")
|
||||
subparsers = parser.add_subparsers(dest='command', help='Available commands')
|
||||
|
||||
Reference in New Issue
Block a user