Skip to content

Commit bb9b934

Browse files
committed
feat: add Python type hints to generator modules
- Add type hints to dashboard.py functions - Add type hints to rss.py functions - Add type hints to schema.py functions - Enable mypy checking for generator modules Improves code quality and IDE support across generators.
1 parent dab0d80 commit bb9b934

3 files changed

Lines changed: 53 additions & 53 deletions

File tree

‎src/generators/dashboard.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import logging
88
from pathlib import Path
9-
from typing import Dict, Any, List
9+
from typing import Dict, Any, List, Optional
1010
from datetime import datetime
1111

1212
# Configure logging
@@ -20,9 +20,9 @@
2020
class DashboardGenerator:
2121
"""Generates interactive code analysis dashboard"""
2222

23-
def __init__(self, schemas_path: Path, quality_path: Path = None,
24-
coverage_path: Path = None, dependency_path: Path = None,
25-
cache_dir: Path = None):
23+
def __init__(self, schemas_path: Path, quality_path: Optional[Path] = None,
24+
coverage_path: Optional[Path] = None, dependency_path: Optional[Path] = None,
25+
cache_dir: Optional[Path] = None):
2626
self.schemas_path = schemas_path
2727
self.quality_path = quality_path
2828
self.coverage_path = coverage_path
@@ -38,11 +38,11 @@ def __init__(self, schemas_path: Path, quality_path: Path = None,
3838
# Load performance data
3939
self.performance_data = self._load_performance_data()
4040

41-
def _load_json(self, path: Path) -> Dict[str, Any]:
41+
def _load_json(self, path: Optional[Path]) -> Dict[str, Any]:
4242
"""Load JSON file"""
4343
if path and path.exists():
4444
with open(path, 'r') as f:
45-
return json.load(f)
45+
return json.load(f) # type: ignore[no-any-return]
4646
return {}
4747

4848
def _load_performance_data(self) -> Dict[str, Any]:
@@ -664,7 +664,7 @@ def _generate_performance_section(self) -> str:
664664
</div>
665665
"""
666666

667-
def save_dashboard(self, output_path: Path):
667+
def save_dashboard(self, output_path: Path) -> None:
668668
"""Save dashboard to file"""
669669
html = self.generate_html()
670670

@@ -674,7 +674,7 @@ def save_dashboard(self, output_path: Path):
674674
logger.info(f"✅ Dashboard saved to {output_path}")
675675
logger.info(f" Open in browser: file://{output_path.absolute()}")
676676

677-
def main():
677+
def main() -> None:
678678
import argparse
679679

680680
parser = argparse.ArgumentParser(description='Dashboard Generator')

‎src/generators/rss.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ def _create_item(self, channel: ET.Element, commit: Dict[str, Any], link: str) -
180180
self._add_item_metadata(item, commit, link)
181181
self._add_item_content(item, commit, link)
182182

183-
def _add_item_metadata(self, item: ET.Element, commit: Dict[str, Any], link: str):
183+
def _add_item_metadata(self, item: ET.Element, commit: Dict[str, Any], link: str) -> None:
184184
"""Add basic item metadata"""
185185
ET.SubElement(item, 'title').text = commit['message']
186186
ET.SubElement(item, 'link').text = f"{link}/commit/{commit['hash']}"
187187
ET.SubElement(item, 'guid', isPermaLink='true').text = f"{link}/commit/{commit['hash']}"
188188
ET.SubElement(item, 'pubDate').text = datetime.fromisoformat(commit['date']).strftime('%a, %d %b %Y %H:%M:%S %z')
189189
ET.SubElement(item, 'author').text = f"{commit['email']} ({commit['author']})"
190190

191-
def _add_item_content(self, item: ET.Element, commit: Dict[str, Any], link: str):
191+
def _add_item_content(self, item: ET.Element, commit: Dict[str, Any], link: str) -> None:
192192
"""Add content to item with stats and schema.org markup"""
193193
stats = self.analyze_commit_changes(commit['hash'])
194194
description = self._build_description(commit, stats)
@@ -242,7 +242,7 @@ def _format_xml(self, rss: ET.Element) -> str:
242242
dom = minidom.parseString(xml_str)
243243
return dom.toprettyxml(indent=' ')
244244

245-
def save_rss(self, output_path: Path, **kwargs):
245+
def save_rss(self, output_path: Path, **kwargs: Any) -> None:
246246
"""Save RSS feed to file"""
247247
rss_xml = self.generate_rss_xml(**kwargs)
248248

@@ -252,7 +252,7 @@ def save_rss(self, output_path: Path, **kwargs):
252252
logger.info(f"✅ RSS feed saved to {output_path}")
253253
logger.info(f" {len(self.get_recent_commits())} commits included")
254254

255-
def main():
255+
def main() -> None:
256256
import argparse
257257

258258
parser = argparse.ArgumentParser(description='RSS Feed Generator')

0 commit comments

Comments
 (0)