class Transformer(ast.NodeTransformer): wrapperAST = astor.code_to_ast(print_info) def visit_ClassDef(self, node): return node # Don't add decorators to Class methods def visit_FunctionDef(self, node): self.generic_visit(node) node.decorator_list.append(ast.Call(ast.Name(id="print_info"), args=[], keywords=[])) return node
def minLength(f): _ast = astor.code_to_ast(f) walker = ChangeIf() walker.walk(_ast) return li
def docstring_dbg(): print(astor.dump_tree(astor.code_to_ast(func)))
def ast_class0(): """AST tree of an empty class""" return astor.code_to_ast("class MyClass: pass").body[0]
branch distance = 이미 만들어 놓음 fitness = app. v + branch distance +-1인풋에 대해서도 함. Q. assignment 어케 업데이트 함? Q. While loop 어케 처리 함? ''' #import sys import astor import ast from tree_walk import * from target import func if __name__ == '__main__': _ast = astor.code_to_ast(func) #print(func(1, 2)) class walker(TreeWalk): def __init__(self, node): self.node = node def pre_If(self): pass #a = walker(root) #print(a) #for node in a.walk(root):
import astor def hello(): print('hello!') return _ast = astor.code_to_ast(hello) print(_ast.body[0].value.args[0].s) #_ast.body[0].value.args[0].s = "arrrgh!" exec(astor.to_source(_ast)) hello()
def test_can_locate_method(self): dummy = DummyClass() _ = astor.code_to_ast(dummy.__init__) _ = astor.code_to_ast(dummy.foo())