| import ast |
| from typing import List, Dict |
|
|
| class CodeAnalyzer: |
| def __init__(self): |
| self.issues = [] |
| |
| def analyze_python(self, code: str) -> List[Dict]: |
| try: |
| tree = ast.parse(code) |
| return self._analyze_ast(tree) |
| except SyntaxError as e: |
| return [{"type": "syntax_error", "message": str(e)}] |
| |
| def _analyze_ast(self, tree: ast.AST) -> List[Dict]: |
| issues = [] |
| for node in ast.walk(tree): |
| if isinstance(node, ast.Try): |
| issues.append({ |
| "type": "suggestion", |
| "message": "Consider adding specific exception handlers" |
| }) |
| return issues |
|
|