def definition(correct, correct_start, path): should_be = set() for match in re.finditer('(?:[^ ]+)', correct): string = match.group(0) parser = grammar36.parse(string, start_symbol='eval_input', error_recovery=False) parser_utils.move(parser.get_root_node(), self.line_nr) element = parser.get_root_node() module_context = script._get_module() # The context shouldn't matter for the test results. user_context = get_user_scope(module_context, (self.line_nr, 0)) if user_context.api_type == 'function': user_context = user_context.get_function_execution() element.parent = user_context.tree_node results = try_stubs_to_actual_context_set( evaluator.eval_element(user_context, element), prefer_stub_to_compiled=True) if not results: raise Exception('Could not resolve %s on line %s' % (match.string, self.line_nr - 1)) should_be |= set( Definition(evaluator, r.name) for r in results) debug.dbg('Finished getting types', color='YELLOW') # Because the objects have different ids, `repr`, then compare. should = set(comparison(r) for r in should_be) return should
def evaluate_goto_definition(evaluator, context, leaf, prefer_stubs=False): if leaf.type == 'name': # In case of a name we can just use goto_definition which does all the # magic itself. if prefer_stubs: return evaluator.goto_stub_definitions(context, leaf) else: return evaluator.goto_definitions(context, leaf) parent = leaf.parent definitions = NO_CONTEXTS if parent.type == 'atom': definitions = context.eval_node(leaf.parent) elif parent.type == 'trailer': definitions = evaluate_call_of_leaf(context, leaf) elif isinstance(leaf, tree.Literal): return eval_atom(context, leaf) elif leaf.type in ('fstring_string', 'fstring_start', 'fstring_end'): return get_string_context_set(evaluator) if prefer_stubs: return definitions from jedi.evaluate.gradual.conversion import try_stubs_to_actual_context_set return try_stubs_to_actual_context_set( definitions, prefer_stub_to_compiled=True, )
def infer(self): if not self._name.is_context_name: return [] # Param names are special because they are not handled by # the evaluator method. context_set = try_stubs_to_actual_context_set( self._name.infer(), prefer_stub_to_compiled=True, ) return [Definition(self._evaluator, d.name) for d in context_set]
def goto_definitions(self, context, name): # We don't want stubs here we want the actual contexts, if possible. return try_stubs_to_actual_context_set( self.goto_stub_definitions(context, name), prefer_stub_to_compiled=True )