forked from wavetermdev/waveterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcro-Geniu .py
48 lines (41 loc) · 1.64 KB
/
Acro-Geniu .py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[](https://github.com/coders33123/waveterm/actions/workflows/deploy-docsite.yml)
import ast
def analyze_code(code: str) -> dict:
"""
Analyzes Python code and extracts information about functions, classes, etc.
"""
tree = ast.parse(code)
info = {"functions": [], "classes": [], "variables": []}
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
function_info = {
"name": node.name,
"args": [arg.arg for arg in node.args.args],
"return_type": None, # Needs further analysis
}
info["functions"].append(function_info)
elif isinstance(node, ast.ClassDef):
class_info = {"name": node.name, "methods": []}
for body_node in node.body:
if isinstance(body_node, ast.FunctionDef):
class_info["methods"].append(body_node.name)
info["classes"].append(class_info)
elif isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name):
var_info = {"name": target.id, "type": None} # Needs further analysis
info["variables"].append(var_info)
return info
# Example usage
code_snippet = """
def greet(name: str) -> str:
return f"Hello, {name}!"
class MyClass:
def __init__(self, x: int):
self.x = x
def my_method(self):
return self.x * 2
my_var = 10
"""
analysis_result = analyze_code(code_snippet)
print(analysis_result)