(tree)
| 174 | ) |
| 175 | |
| 176 | def parse_tree(tree): |
| 177 | # get contents of module.body if only 1 element |
| 178 | crnt = ( |
| 179 | tree.body[0] |
| 180 | if isinstance(tree, ast.Module) and len(tree.body) == 1 |
| 181 | else tree |
| 182 | ) |
| 183 | |
| 184 | # remove Expr if it exists |
| 185 | return ast.dump(crnt.value if isinstance(crnt, ast.Expr) else crnt) |
| 186 | |
| 187 | stu_rep = parse_tree(state.student_ast) |
| 188 | sol_rep = parse_tree(state.solution_ast if not code else ast.parse(code)) |