def goto_definitions(self): """ Return the definitions of a the path under the cursor. goto function! This follows complicated paths and returns the end, not the first definition. The big difference between :meth:`goto_assignments` and :meth:`goto_definitions` is that :meth:`goto_assignments` doesn't follow imports and statements. Multiple objects may be returned, because Python itself is a dynamic language, which means depending on an option you can have two different versions of a function. :rtype: list of :class:`classes.Definition` """ leaf = self._get_module().name_for_position(self._pos) if leaf is None: leaf = self._get_module().get_leaf_for_position(self._pos) if leaf is None: return [] definitions = helpers.evaluate_goto_definition(self._evaluator, leaf) names = [s.name for s in definitions] defs = [classes.Definition(self._evaluator, name) for name in names] # The additional set here allows the definitions to become unique in an # API sense. In the internals we want to separate more things than in # the API. return helpers.sorted_definitions(set(defs))
def _goto_definitions(self, only_stubs=False, prefer_stubs=False): leaf = self._module_node.get_name_of_position(self._pos) if leaf is None: leaf = self._module_node.get_leaf_for_position(self._pos) if leaf is None: return [] context = self._evaluator.create_context(self._get_module(), leaf) contexts = helpers.evaluate_goto_definition(self._evaluator, context, leaf) contexts = convert_contexts( contexts, only_stubs=only_stubs, prefer_stubs=prefer_stubs, ) defs = [classes.Definition(self._evaluator, c.name) for c in contexts] # The additional set here allows the definitions to become unique in an # API sense. In the internals we want to separate more things than in # the API. return helpers.sorted_definitions(set(defs))