File size: 724 Bytes
bd91486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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