def build_if(): test = menu('test')['test'] test = ast.parse(test).body[0].value add_ast_node(_ast.If( test=test, body=[], orelse=[], ))
def build_for(): config = menu("target", "iterable") target = _ast.Name(id=config["target"]) iterable = ast.parse(config["iterable"]).body[0].value add_ast_node(_ast.For( target=target, iter=iterable, body=[], orelse=[], ))
def build_function(): config = menu('name') name = config['name'] function = _ast.FunctionDef(name=name, args=[], defaults=[], body=[], decorator_list=[]) add_ast_node(function) parent = globals['node'] for child in parent.children: if (child.node == function): globals['node'] = child break
def build_expr(): expression = menu('expression')['expression'] expression = ast.parse(expression).body[0] add_ast_node(expression)
def build_import(): module = menu('module')['module'] add_ast_node(_ast.Import(names=[_ast.alias(name=module, asname=None)]))