Skip to content

Commit 126c61f

Browse files
refactor: Improve type hints and MyPy configuration
- Add explicit type hints to adapters and wizards for better type safety - Update MyPy configuration to exclude non-production directories - Update learned patterns from recent workflow executions Changes: - Code inspection adapters: Add type annotations to findings lists - Wizard modules: Improve type hints across debugging, performance, and security wizards - pyproject.toml: Exclude build/, backend/, scripts/, docs/, and archived directories from MyPy - patterns/: Update debugging patterns and health check memory data Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 299a974 commit 126c61f

18 files changed

Lines changed: 2370 additions & 1076 deletions

agents/code_inspection/adapters/code_health_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def analyze(self) -> ToolResult:
5959
report = await runner.run_all()
6060

6161
# Convert findings to unified format
62-
findings = []
62+
findings: list[dict[str, Any]] = []
6363
findings_by_severity: dict[str, int] = {
6464
"critical": 0,
6565
"high": 0,

agents/code_inspection/adapters/code_review_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async def analyze(
151151
report = await wizard.analyze(context)
152152

153153
# Convert findings to unified format
154-
findings = []
154+
findings: list[dict[str, Any]] = []
155155
findings_by_severity: dict[str, int] = {
156156
"critical": 0,
157157
"high": 0,

agents/code_inspection/adapters/debugging_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async def analyze_memory_enhanced(self) -> ToolResult:
5151

5252
start_time = time.time()
5353

54-
findings = []
54+
findings: list[dict[str, Any]] = []
5555
findings_by_severity: dict[str, int] = {
5656
"critical": 0,
5757
"high": 0,
@@ -161,7 +161,7 @@ async def analyze_advanced(self) -> ToolResult:
161161
)
162162

163163
# Convert to unified format
164-
findings = []
164+
findings: list[dict[str, Any]] = []
165165
findings_by_severity: dict[str, int] = {
166166
"critical": 0,
167167
"high": 0,

agents/code_inspection/adapters/security_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def analyze(self) -> ToolResult:
5959
scanner = VulnerabilityScanner()
6060

6161
# Collect all findings
62-
findings = []
62+
findings: list[dict[str, Any]] = []
6363
findings_by_severity: dict[str, int] = {
6464
"critical": 0,
6565
"high": 0,

agents/code_inspection/adapters/tech_debt_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def analyze(self) -> ToolResult:
6262
)
6363

6464
# Convert findings to unified format
65-
findings = []
65+
findings: list[dict[str, Any]] = []
6666
findings_by_severity: dict[str, int] = {
6767
"critical": 0,
6868
"high": 0,
@@ -143,7 +143,7 @@ async def _fallback_analyze(self, start_time: float) -> ToolResult:
143143
"XXX": re.compile(r"#\s*XXX[:\s](.*)$", re.IGNORECASE | re.MULTILINE),
144144
}
145145

146-
findings = []
146+
findings: list[dict[str, Any]] = []
147147
findings_by_severity: dict[str, int] = {
148148
"critical": 0,
149149
"high": 0,

agents/code_inspection/adapters/test_quality_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def analyze(self) -> ToolResult:
5454
analyzer = TestQualityAnalyzer()
5555

5656
# Collect all findings
57-
findings = []
57+
findings: list[dict[str, Any]] = []
5858
findings_by_severity: dict[str, int] = {
5959
"critical": 0,
6060
"high": 0,

agents/code_inspection/nodes/dynamic_analysis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import asyncio
1616
import logging
1717
from datetime import datetime
18+
from typing import Any
1819

1920
from ..adapters import CodeReviewAdapter, DebuggingAdapter
2021
from ..state import CodeInspectionState, InspectionPhase, add_audit_entry
@@ -41,7 +42,7 @@ async def run_dynamic_analysis(state: CodeInspectionState) -> CodeInspectionStat
4142
enabled_tools = state["enabled_tools"]
4243

4344
# Get security context from Phase 1 for informed review
44-
security_context = []
45+
security_context: list[dict[str, Any]] = []
4546
if state.get("security_scan_result"):
4647
security_context = state["security_scan_result"].get("findings", [])
4748

empathy_software_plugin/wizards/advanced_debugging_wizard.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def __init__(self):
4747
super().__init__()
4848
self.bug_analyzer = BugRiskAnalyzer()
4949
self.pattern_library = get_pattern_library()
50-
self._name = "Advanced Debugging Wizard"
51-
self._level = 4
50+
self._name: str = "Advanced Debugging Wizard"
51+
self._level: int = 4
5252

5353
@property
5454
def name(self) -> str:
@@ -126,7 +126,8 @@ async def analyze(self, context: dict[str, Any]) -> dict[str, Any]:
126126
# Phase 4: Group by fixability
127127
fixability_by_linter = {}
128128
for linter_name, result in linter_results.items():
129-
fixability = group_issues_by_fixability(linter_name, result["issues"])
129+
issues_for_fixability: list[LintIssue] = result["issues"] # type: ignore[assignment]
130+
fixability = group_issues_by_fixability(linter_name, issues_for_fixability)
130131
fixability_by_linter[linter_name] = {
131132
"auto_fixable": len(fixability["auto_fixable"]),
132133
"manual": len(fixability["manual"]),
@@ -138,7 +139,8 @@ async def analyze(self, context: dict[str, Any]) -> dict[str, Any]:
138139
logger.info("Applying auto-fixes...")
139140

140141
for linter_name, result in linter_results.items():
141-
fixes = apply_fixes(linter_name, result["issues"], dry_run=False, auto_only=True)
142+
issues_for_fixing: list[LintIssue] = result["issues"] # type: ignore[assignment]
143+
fixes = apply_fixes(linter_name, issues_for_fixing, dry_run=False, auto_only=True)
142144

143145
successful = [f for f in fixes if f.success]
144146
failed = [f for f in fixes if not f.success]
@@ -155,7 +157,8 @@ async def analyze(self, context: dict[str, Any]) -> dict[str, Any]:
155157
logger.info("Verifying fixes...")
156158

157159
for linter_name, result in linter_results.items():
158-
verification = verify_fixes(linter_name, project_path, result["issues"])
160+
issues_for_verification: list[LintIssue] = result["issues"] # type: ignore[assignment]
161+
verification = verify_fixes(linter_name, project_path, issues_for_verification)
159162

160163
verification_results[linter_name] = verification.to_dict()
161164

@@ -201,7 +204,7 @@ def _generate_cross_language_insights(self, issues: list[LintIssue]) -> list[dic
201204
insights = []
202205

203206
# Group issues by language
204-
by_language = {}
207+
by_language: dict[str, list[LintIssue]] = {}
205208
for issue in issues:
206209
lang = issue.linter
207210
if lang not in by_language:

empathy_software_plugin/wizards/debugging/bug_risk_analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def generate_summary(self, assessments: list[RiskAssessment]) -> dict[str, Any]:
335335
This is the Level 4 alert format.
336336
"""
337337
# Count by risk level
338-
by_risk = {
338+
by_risk: dict[BugRisk, list[RiskAssessment]] = {
339339
BugRisk.CRITICAL: [],
340340
BugRisk.HIGH: [],
341341
BugRisk.MEDIUM: [],

empathy_software_plugin/wizards/debugging/config_loaders.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,19 @@ def _load_pyproject(self, path: Path) -> LintConfig:
246246
"""Load from pyproject.toml"""
247247
try:
248248
import tomli
249+
250+
toml_loader = tomli
249251
except ImportError:
250252
# Fallback for Python 3.11+
251253
try:
252-
import tomllib as tomli
254+
import tomllib
255+
256+
toml_loader = tomllib
253257
except ImportError as e:
254258
raise ImportError("tomli or tomllib required for pyproject.toml") from e
255259

256260
with open(path, "rb") as f:
257-
data = tomli.load(f)
261+
data = toml_loader.load(f)
258262

259263
pylint_config = data.get("tool", {}).get("pylint", {})
260264

0 commit comments

Comments
 (0)