def collectLoopVars(n): if isinstance(n, ast.Name): vars.append(n.id) elif isinstance(n, ast.expr_context): return else: for c in ast.iter_child_nodes(n): collectLoopVars(c)
def TRY(self, node): handler_names = [] # List the exception handlers for handler in node.handlers: if isinstance(handler.type, ast.Tuple): for exc_type in handler.type.elts: handler_names.append(node_name(exc_type)) elif handler.type: handler_names.append(node_name(handler.type)) # Memorize the except handlers and process the body self.except_handlers.append(handler_names) for child in node.body: self.handleNode(child, node) self.except_handlers.pop() # Process the other nodes: "except:", "else:", "finally:" for child in ast.iter_child_nodes(node): if child not in node.body: self.handleNode(child, node)
def handle_children(self, tree): for node in ast.iter_child_nodes(tree): self.handleNode(node, tree)