@@ -16,6 +16,7 @@ def __init__(self, obj, method, subMethod=False):
1616 self .needed_keys = set ()
1717 self .needed_methods = {}
1818 self .subMethod = subMethod
19+ self .needed_globals = {}
1920
2021 def visit_Return (self , node ):
2122 if self .subMethod :
@@ -73,9 +74,15 @@ def visit_Attribute(self, node):
7374
7475 return ast .fix_missing_locations (new_node )
7576
76- method_name = f"{ self .obj .name } _{ node .attr } "
77- new_node = ast .copy_location (ast .Name (id = method_name , ctx = node .ctx ), node )
78- self .needed_methods [method_name ] = node .attr
77+ if callable (stateVal ):
78+ method_name = f"{ self .obj .name } _{ node .attr } "
79+ new_node = ast .copy_location (ast .Name (id = method_name , ctx = node .ctx ), node )
80+ self .needed_methods [method_name ] = node .attr
81+ return ast .fix_missing_locations (new_node )
82+
83+ attr_name = f"{ self .obj .name } _{ node .attr } "
84+ new_node = ast .copy_location (ast .Name (id = attr_name , ctx = node .ctx ), node )
85+ self .needed_globals [attr_name ] = stateVal
7986 return ast .fix_missing_locations (new_node )
8087
8188 return node
@@ -90,6 +97,19 @@ def visit_Call(self, node):
9097
9198 return node
9299
100+ # def visit_Assign(self, node):
101+ # for target in node.targets:
102+ # if isinstance(target, ast.Name):
103+ # target.id = f"{self.obj.name}_{target.id}"
104+ # self.local_vars.add(target.id)
105+ # return self.generic_visit(node)
106+ #
107+ #
108+ # def visit_Name(self, node):
109+ # # if node.id in self.local_vars:
110+ # # node.id = f"{self.obj.name}_{node.id}"
111+ # return node
112+
93113 def visit_Expr (self , node ):
94114 node = self .generic_visit (node )
95115 if isinstance (node .value , ast .Call ):
@@ -163,7 +183,7 @@ def visit_If(self, node):
163183 try :
164184 value = eval (compiled , {}, {"self" : self .obj })
165185 except Exception as e :
166- raise RuntimeError ("Can not evaluate conditional" )
186+ raise RuntimeError (f"On { self . obj . name } : { self . method . __name__ } can not evaluate conditional\n { ast . unparse ( node ) } " )
167187
168188 case = (node .body if value else node .orelse )
169189 new_body = []
0 commit comments