| 36 | |
| 37 | |
| 38 | def _ast_node(node: ast.AST) -> dict: |
| 39 | children = {} |
| 40 | fields = {} |
| 41 | for field, value in ast.iter_fields(node): |
| 42 | if isinstance(value, list): |
| 43 | if value and all(isinstance(item, ast.AST) for item in value): |
| 44 | children[field] = [_ast_node(item) for item in value] |
| 45 | else: |
| 46 | fields[field] = str(value) if value else [] |
| 47 | elif isinstance(value, ast.AST): |
| 48 | children[field] = [_ast_node(value)] |
| 49 | else: |
| 50 | fields[field] = value if isinstance(value, (int, float, str, bool)) or value is None else str(value) |
| 51 | return {"node_type": node.__class__.__name__, "children": children, "fields": fields} |
| 52 | |
| 53 | |
| 54 | def _has_property(node: dict, path: list[str], expected: str) -> bool: |