Skip to content

Commit 091ecea

Browse files
GeneAIclaude
authored andcommitted
refactor: Professional code quality improvements (Option 2)
Code Quality Enhancements: 1. Logging Improvements (48 changes) - Replaced all print() statements in cli.py with structured logging - Used logger.info() for success/status messages - Used logger.error() for error messages - Improved log consistency and management 2. Exception Handling (25 fixes) - Fixed all bare except clauses in wizard files - Changed `except:` to `except OSError:` for file I/O operations - Improved debuggability and error visibility - Files: agent_orchestration, ai_collaboration, ai_documentation, multi_model, prompt_engineering, rag_pattern wizards 3. Documentation (5 abstract methods) - Added comprehensive Google-style docstrings to all abstract methods - Enhanced EmpathyLevel.respond() with implementation guidance - Documented BaseWizard.analyze() and get_required_context() - Documented BasePlugin.get_metadata() and register_wizards() - Added 149 lines of developer guidance 4. Code Modernization (1 fix) - Removed outdated Python 3.9 compatibility code from registry.py - Aligned with project's Python 3.10+ requirement - Cleaned up unnecessary version checking Impact: - Better logging: 48 print() → logger calls for structured output - Better errors: 25 bare excepts → specific OSError catching - Better docs: 5 abstract methods with comprehensive guidance - Cleaner code: Removed deprecated version checks Files Modified: 10 Lines Changed: ~200 Code Quality: Significantly improved 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 19ab4ad commit 091ecea

File tree

10 files changed

+226
-115
lines changed

10 files changed

+226
-115
lines changed

empathy_software_plugin/wizards/agent_orchestration_wizard.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def _has_state_management(self, orchestration: list[str]) -> bool:
361361
for kw in ["StateGraph", "AgentState", "shared_state", "TypedDict"]
362362
):
363363
return True
364-
except:
364+
except OSError:
365365
pass
366366
return False
367367

@@ -374,7 +374,7 @@ def _has_agent_error_handling(self, orchestration: list[str]) -> bool:
374374
# Look for error handling patterns
375375
if "try:" in content and "agent" in content.lower():
376376
return True
377-
except:
377+
except OSError:
378378
pass
379379
return False
380380

@@ -421,7 +421,7 @@ def _all_sequential(self, orchestration: list[str]) -> bool:
421421
for kw in ["asyncio.gather", "ThreadPool", "parallel", "concurrent"]
422422
):
423423
return False
424-
except:
424+
except OSError:
425425
pass
426426
return True
427427

@@ -442,6 +442,6 @@ def _has_observability(self, orchestration: list[str]) -> bool:
442442
kw in content for kw in ["logger", "trace", "span", "metrics", "telemetry"]
443443
):
444444
return True
445-
except:
445+
except OSError:
446446
pass
447447
return False

empathy_software_plugin/wizards/ai_collaboration_wizard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def _detect_reactive_patterns(self, files: list[str]) -> int:
445445
if "ai.generate" in content or "openai." in content or "anthropic." in content:
446446
if "context" not in content.lower() and "history" not in content.lower():
447447
reactive_count += 1
448-
except:
448+
except OSError:
449449
pass
450450
return reactive_count
451451

@@ -494,6 +494,6 @@ def _has_any_keyword(self, files: list[str], keywords: list[str]) -> bool:
494494
content = f.read()
495495
if any(kw in content for kw in keywords):
496496
return True
497-
except:
497+
except OSError:
498498
pass
499499
return False

empathy_software_plugin/wizards/ai_documentation_wizard.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def _analyze_ai_documentation_quality(
9999
try:
100100
with open(doc_file) as f:
101101
content = f.read()
102-
except:
102+
except OSError:
103103
continue
104104

105105
# AI needs explicit architecture context
@@ -161,7 +161,7 @@ async def _analyze_ai_documentation_quality(
161161
try:
162162
with open(code_file) as f:
163163
content = f.read()
164-
except:
164+
except OSError:
165165
continue
166166

167167
# Check for missing type hints (AI relies on these)
@@ -453,7 +453,7 @@ def _has_explicit_conventions(self, doc_files: list[str]) -> bool:
453453
with open(filepath) as f:
454454
if "convention" in f.read().lower():
455455
return True
456-
except:
456+
except OSError:
457457
pass
458458
return False
459459

@@ -473,7 +473,7 @@ def _calculate_why_ratio(self, doc_files: list[str]) -> float:
473473
why_sections += content.lower().count("rationale")
474474
why_sections += content.lower().count("decision")
475475
why_chars += why_sections * 100 # Estimate
476-
except:
476+
except OSError:
477477
pass
478478

479479
if total_chars == 0:

empathy_software_plugin/wizards/multi_model_wizard.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def _has_model_abstraction(self, routing: list[str]) -> bool:
388388
for kw in ["ModelRouter", "ModelRegistry", "AbstractModel", "UnifiedAPI"]
389389
):
390390
return True
391-
except:
391+
except OSError:
392392
pass
393393
return False
394394

@@ -400,7 +400,7 @@ def _has_fallback_strategy(self, routing: list[str]) -> bool:
400400
content = f.read()
401401
if "fallback" in content.lower() or "retry" in content.lower():
402402
return True
403-
except:
403+
except OSError:
404404
pass
405405
return False
406406

@@ -419,7 +419,7 @@ def _has_cost_tracking(self, routing: list[str]) -> bool:
419419
"track" in content.lower() or "log" in content.lower()
420420
):
421421
return True
422-
except:
422+
except OSError:
423423
pass
424424
return False
425425

@@ -434,7 +434,7 @@ def _has_performance_monitoring(self, routing: list[str]) -> bool:
434434
for kw in ["latency", "metrics", "monitoring", "telemetry"]
435435
):
436436
return True
437-
except:
437+
except OSError:
438438
pass
439439
return False
440440

@@ -446,7 +446,7 @@ def _has_cost_optimization(self, routing: list[str]) -> bool:
446446
content = f.read()
447447
if "cache" in content.lower() or "budget" in content.lower():
448448
return True
449-
except:
449+
except OSError:
450450
pass
451451
return False
452452

@@ -458,7 +458,7 @@ def _has_output_validation(self, routing: list[str]) -> bool:
458458
content = f.read()
459459
if any(kw in content for kw in ["Pydantic", "validate", "schema", "BaseModel"]):
460460
return True
461-
except:
461+
except OSError:
462462
pass
463463
return False
464464

@@ -471,7 +471,7 @@ def _has_version_tracking(self, routing: list[str]) -> bool:
471471
# Look for specific version strings
472472
if "gpt-4-" in content or "claude-3" in content or "version" in content.lower():
473473
return True
474-
except:
474+
except OSError:
475475
pass
476476
return False
477477

@@ -492,6 +492,6 @@ def _has_smart_routing(self, routing: list[str]) -> bool:
492492
]
493493
):
494494
return True
495-
except:
495+
except OSError:
496496
pass
497497
return False

empathy_software_plugin/wizards/prompt_engineering_wizard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,13 @@ def _has_version_marker(self, filepath: str) -> bool:
414414
with open(filepath) as f:
415415
content = f.read()
416416
return bool(re.search(r"v\d+\.\d+\.\d+|version:", content, re.IGNORECASE))
417-
except:
417+
except OSError:
418418
return False
419419

420420
def _estimate_token_count(self, filepath: str) -> int:
421421
"""Rough estimate of token count (chars / 4)"""
422422
try:
423423
with open(filepath) as f:
424424
return len(f.read()) // 4
425-
except:
425+
except OSError:
426426
return 0

empathy_software_plugin/wizards/rag_pattern_wizard.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def _has_reranking(self, rag_impl: list[str]) -> bool:
387387
kw in content.lower() for kw in ["rerank", "cross-encoder", "cohere.rerank"]
388388
):
389389
return True
390-
except:
390+
except OSError:
391391
pass
392392
return False
393393

@@ -399,7 +399,7 @@ def _has_hybrid_search(self, rag_impl: list[str]) -> bool:
399399
content = f.read()
400400
if any(kw in content.lower() for kw in ["hybrid", "bm25", "keyword", "fusion"]):
401401
return True
402-
except:
402+
except OSError:
403403
pass
404404
return False
405405

@@ -414,7 +414,7 @@ def _has_query_understanding(self, rag_impl: list[str]) -> bool:
414414
for kw in ["query_rewrite", "query_expansion", "decompose", "intent"]
415415
):
416416
return True
417-
except:
417+
except OSError:
418418
pass
419419
return False
420420

@@ -429,7 +429,7 @@ def _has_evaluation(self, rag_impl: list[str]) -> bool:
429429
for kw in ["evaluate", "metrics", "ground_truth", "precision", "recall"]
430430
):
431431
return True
432-
except:
432+
except OSError:
433433
pass
434434
return False
435435

@@ -444,6 +444,6 @@ def _has_context_optimization(self, rag_impl: list[str]) -> bool:
444444
for kw in ["prune", "summarize", "deduplicate", "context_budget"]
445445
):
446446
return True
447-
except:
447+
except OSError:
448448
pass
449449
return False

0 commit comments

Comments
 (0)