Beispiel #1
0
    def goto_assignments(self,
                         follow_imports=False,
                         follow_builtin_imports=False):
        """
        Return the first definition found, while optionally following imports.
        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.

        :param follow_imports: The goto call will follow imports.
        :param follow_builtin_imports: If follow_imports is True will decide if
            it follow builtin imports.
        :rtype: list of :class:`classes.Definition`
        """
        def filter_follow_imports(names, check):
            for name in names:
                if check(name):
                    new_names = list(filter_follow_imports(name.goto(), check))
                    found_builtin = False
                    if follow_builtin_imports:
                        for new_name in new_names:
                            if new_name.start_pos is None:
                                found_builtin = True

                    if found_builtin:
                        yield name
                    else:
                        for new_name in new_names:
                            yield new_name
                else:
                    yield name

        tree_name = self._module_node.get_name_of_position(self._pos)
        if tree_name is None:
            # Without a name we really just want to jump to the result e.g.
            # executed by `foo()`, if we the cursor is after `)`.
            return self.goto_definitions()
        context = self._evaluator.create_context(self._get_module(), tree_name)
        names = list(self._evaluator.goto(context, tree_name))

        if follow_imports:
            names = filter_follow_imports(names, lambda name: name.is_import())
        names = try_stub_to_actual_names(names, prefer_stub_to_compiled=True)

        defs = [classes.Definition(self._evaluator, d) for d in set(names)]
        return helpers.sorted_definitions(defs)
Beispiel #2
0
 def goto(self, context, name):
     names = self._goto(context, name)
     names = try_stub_to_actual_names(names, prefer_stub_to_compiled=True)
     return names
Beispiel #3
0
 def goto(self):
     from jedi.evaluate.gradual.conversion import try_stub_to_actual_names
     return try_stub_to_actual_names([self._context.name])