Coverage for code_outline.py: 29%

25 statements  

« prev     ^ index     » next       coverage.py v7.2.5, created at 2023-05-11 13:22 -0700

1from ast import NodeVisitor 

2 

3class DefinitionNode(): 

4 def __init__(self, name, type, line_start, line_end, indentation): 

5 self.name = name 

6 self.type = type 

7 self.line_start = line_start 

8 self.line_end = line_end 

9 self.indentation = indentation 

10 

11class ClassFuncNodeVisitor(NodeVisitor): 

12 def __init__(self): 

13 self.node_list = [] 

14 

15 def visit_ClassDef(self, node): 

16 self.node_list.append(DefinitionNode(node.name, "class", node.lineno, node.end_lineno, node.col_offset)) 

17 for child in node.body: 

18 self.visit(child) 

19 def visit_FunctionDef(self, node): 

20 self.node_list.append(DefinitionNode(node.name, "func", node.lineno, node.end_lineno, node.col_offset)) 

21 for child in node.body: 

22 self.visit(child) 

23 def visit_AsyncFunctionDef(self, node): 

24 self.node_list.append(DefinitionNode(node.name, "async func", node.lineno, node.end_lineno, node.col_offset)) 

25 for child in node.body: 

26 self.visit(child) 

27 def get_node_list(self): 

28 return self.node_list