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