| @@ 32-42 (lines=11) @@ | ||
| 29 | yield from _ast_nodes(ast.iter_child_nodes(item)) |
|
| 30 | ||
| 31 | ||
| 32 | def _ast_edge(parsed_ast: AST): |
|
| 33 | for child_ast in ast.iter_child_nodes(parsed_ast): |
|
| 34 | if not isinstance(child_ast, ast.Load): |
|
| 35 | edge = {'source': parsed_ast, 'target': child_ast} |
|
| 36 | edge_types = (field_name for field_name, value in ast.iter_fields(parsed_ast) if |
|
| 37 | child_ast == value or (child_ast in value if isinstance(value, list) else False)) |
|
| 38 | edge_type = next(edge_types, None) |
|
| 39 | if edge_type: |
|
| 40 | edge['type'] = edge_type |
|
| 41 | yield edge |
|
| 42 | yield from _ast_edge(child_ast) |
|
| 43 | ||
| 44 | ||
| 45 | @pytest.fixture() |
|
| @@ 20-30 (lines=11) @@ | ||
| 17 | yield from _ast_nodes(ast.iter_child_nodes(item)) |
|
| 18 | ||
| 19 | ||
| 20 | def _ast_edge(parsed_ast: AST): |
|
| 21 | for child_ast in ast.iter_child_nodes(parsed_ast): |
|
| 22 | if not isinstance(child_ast, ast.Load): |
|
| 23 | edge = {'source': parsed_ast, 'target': child_ast} |
|
| 24 | edge_types = (field_name for field_name, value in ast.iter_fields(parsed_ast) if |
|
| 25 | child_ast == value or (child_ast in value if isinstance(value, list) else False)) |
|
| 26 | edge_type = next(edge_types, None) |
|
| 27 | if edge_type: |
|
| 28 | edge['type'] = edge_type |
|
| 29 | yield edge |
|
| 30 | yield from _ast_edge(child_ast) |
|
| 31 | ||
| 32 | ||
| 33 | def ast_graph_model(): |
|