def assigns(self): return Parser( None, [ flatten(node) for node in self.execute("$.body[@.type is 'Assign']").n ], )
def last_line(self): return flatten(self.nodes["body"][-1])
def query_raw(self, pattern): nodes = Template(pattern).process(self.code, True) if isinstance(nodes, list) and len(nodes) == 1: nodes = [flatten(convert_node(node)) for node in nodes[0].body] return Parser(None, nodes)
def for_(self): for_body = self.execute("$.body[@.type is 'For'].body").n iterators = self.execute("$.body[@.type is 'For'].(target, iter)").n return Parser(None, [flatten(for_body), flatten(iterators)])
def returns_call(self): return Parser(None, [flatten(self.execute("$.body[@.type is 'Return']").n)])
def decorators(self): return Parser(None, [flatten(self.execute("$.decorator_list").n)])
def assign_(self): return Parser(None, [flatten(self.execute("$.body[@.type is 'Assign']").n)])
def calls(self): nodes = self.execute( "$.body[@.type is 'Expr' and @.value.type is 'Call']").n node_list = [nodes] if isinstance(nodes, dict) else nodes return Parser(None, [flatten(node) for node in node_list])
def assign_to(self): nodes = self.execute("$.body[@.type is 'Assign']").n if isinstance(nodes, dict): return Parser(None, [flatten(nodes)]) else: return Parser(None, [flatten(node) for node in nodes])