def get_posibilities(module, func_name): try: possible_stmts = module.used_names[func_name] except KeyError: return [] for stmt in possible_stmts: if not isinstance(stmt, parsing.Import): calls = _scan_array(stmt.get_assignment_calls(), func_name) for c in calls: # no execution means that params cannot be set call_path = c.generate_call_path() pos = c.start_pos scope = stmt.parent evaluate.follow_call_path(call_path, scope, pos) return listener.param_possibilities
def get_posibilities(module, func_name): try: possible_stmts = module.used_names[func_name] except KeyError: return [] for stmt in possible_stmts: if isinstance(stmt, pr.Import): continue calls = _scan_statement(stmt, func_name) for c in calls: # no execution means that params cannot be set call_path = list(c.generate_call_path()) pos = c.start_pos scope = stmt.parent # this whole stuff is just to not execute certain parts # (speed improvement), basically we could just call # ``follow_call_path`` on the call_path and it would # also work. def listRightIndex(lst, value): return len(lst) - lst[-1::-1].index(value) - 1 # Need to take right index, because there could be a # func usage before. i = listRightIndex(call_path, func_name) first, last = call_path[:i], call_path[i + 1:] if not last and not call_path.index(func_name) != i: continue scopes = [scope] if first: scopes = evaluate.follow_call_path( iter(first), scope, pos) pos = None for scope in scopes: s = evaluate.find_name(scope, func_name, position=pos, search_global=not first, resolve_decorator=False) c = [ getattr(escope, 'base_func', None) or escope.base for escope in s if escope.isinstance(er.Function, er.Class) ] if compare in c: # only if we have the correct function we execute # it, otherwise just ignore it. evaluate.follow_paths(iter(last), s, scope) return listener.param_possibilities
def get_posibilities(module, func_name): try: possible_stmts = module.used_names[func_name] except KeyError: return [] for stmt in possible_stmts: if isinstance(stmt, pr.Import): continue calls = _scan_statement(stmt, func_name) for c in calls: # no execution means that params cannot be set call_path = list(c.generate_call_path()) pos = c.start_pos scope = stmt.parent # this whole stuff is just to not execute certain parts # (speed improvement), basically we could just call # ``follow_call_path`` on the call_path and it would # also work. def listRightIndex(lst, value): return len(lst) - lst[-1::-1].index(value) - 1 # Need to take right index, because there could be a # func usage before. i = listRightIndex(call_path, func_name) first, last = call_path[:i], call_path[i + 1 :] if not last and not call_path.index(func_name) != i: continue scopes = [scope] if first: scopes = evaluate.follow_call_path(iter(first), scope, pos) pos = None for scope in scopes: s = evaluate.find_name( scope, func_name, position=pos, search_global=not first, resolve_decorator=False ) c = [ getattr(escope, "base_func", None) or escope.base for escope in s if escope.isinstance(er.Function, er.Class) ] if compare in c: # only if we have the correct function we execute # it, otherwise just ignore it. evaluate.follow_paths(iter(last), s, scope) return listener.param_possibilities
def check_calls(calls, add_name): """ Calls are processed here. The part before the call is searched and compared with the original Array. """ result = [] for c in calls: call_path = list(c.generate_call_path()) separate_index = call_path.index(add_name) if add_name == call_path[-1] or separate_index == 0: # this means that there is no execution -> [].append # or the keyword is at the start -> append() continue backtrack_path = iter(call_path[:separate_index]) position = c.start_pos scope = c.get_parent_until(pr.IsScope) found = evaluate.follow_call_path(backtrack_path, scope, position) if not compare_array in found: continue params = call_path[separate_index + 1] if not params.values: continue # no params: just ignore it if add_name in ["append", "add"]: for param in params: result += evaluate.follow_statement(param) elif add_name in ["insert"]: try: second_param = params[1] except IndexError: continue else: result += evaluate.follow_statement(second_param) elif add_name in ["extend", "update"]: for param in params: iterators = evaluate.follow_statement(param) result += evaluate.get_iterator_types(iterators) return result
def check_calls(calls, add_name): """ Calls are processed here. The part before the call is searched and compared with the original Array. """ result = [] for c in calls: call_path = list(c.generate_call_path()) separate_index = call_path.index(add_name) if add_name == call_path[-1] or separate_index == 0: # this means that there is no execution -> [].append # or the keyword is at the start -> append() continue backtrack_path = iter(call_path[:separate_index]) position = c.start_pos scope = c.get_parent_until(pr.IsScope) found = evaluate.follow_call_path(backtrack_path, scope, position) if not compare_array in found: continue params = call_path[separate_index + 1] if not params.values: continue # no params: just ignore it if add_name in ['append', 'add']: for param in params: result += evaluate.follow_statement(param) elif add_name in ['insert']: try: second_param = params[1] except IndexError: continue else: result += evaluate.follow_statement(second_param) elif add_name in ['extend', 'update']: for param in params: iterators = evaluate.follow_statement(param) result += evaluate.get_iterator_types(iterators) return result