How to use jedi - 10 common examples

To help you get started, we’ve selected a few jedi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davidhalter / jedi / test / test_api / test_call_signatures.py View on Github external
Github issue #319.
        """
        s = dedent("""\
        def static(func):
            def wrapped(obj, *args):
                return f(type(obj), *args)
            return wrapped

        class C(object):
            @static
            def test(cls):
                return 10

        C().test(""")

        signatures = Script(s).call_signatures()
        assert len(signatures) == 1
        x = [p.description for p in signatures[0].params]
        assert x == ['*args']
github davidhalter / jedi / test / test_parser / test_tokenize.py View on Github external
def test_end_pos_one_line(self):
        parsed = parser.Parser(parser.load_grammar(), dedent(u('''
        def testit():
            a = "huhu"
        ''')))
        tok = parsed.module.subscopes[0].statements[0].children[2]
        assert tok.end_pos == (3, 14)
github davidhalter / jedi / test / test_parser / test_parser.py View on Github external
def get_call(self, source):
        stmt = Parser(u(source), no_docstr=True).module.statements[0]
        return stmt.expression_list()[0]
github notetau / geany-jedi-complete / src / data / jediserver.py View on Github external
return ""
        params = post_data[:idx].split(",")
        if len(params) != 3:
            print("jedi-server/complete: invalid post code=2")
            return ""
        line, column, filename = params
        line, column = int(line), int(column)
        source = post_data[idx + 2:]
        print("jedi-server/complete: ", line, column, filename)

        # do completion
        def print_candidate(type_, typed_text, arguement):
            # row format: type$typed_text$arguemnt
            return "{0}${1}${2}\n".format(type_, typed_text, arguement)

        script = jedi.Script(source, line, column)
        completions = script.completions()
        # output compltion results
        result = ""
        for c in completions:
            if c.type in ["function", "class"]:
                if hasattr(c, "params"):  # c is callable
                    sig = "({0})".format(
                        ", ".join(map(lambda x: x.description, c.params)))
                    result += print_candidate(c.type, c.name, sig)
                else:
                    result += print_candidate(c.type, c.name, "")
            elif c.type in ["statement", "instance", "module", "import", "param"]:
                result += print_candidate(c.type, c.name, "")
            elif c.type == "keyword":
                pass  # ignore keyword
            else:
github konstellation-io / science-toolkit / vscode / extensions / ms-python.python-2020.2.63072 / pythonFiles / completion.py View on Github external
jediPath = sys.argv[2]
        jediPreview = True
        cachePrefix = "custom_v"
        if len(sys.argv) > 3:
            modulesToLoad = sys.argv[3]
    else:
        # release
        jediPath = os.path.join(os.path.dirname(__file__), "lib", "python")
        if len(sys.argv) > 1:
            modulesToLoad = sys.argv[1]

    sys.path.insert(0, jediPath)
    import jedi

    if jediPreview:
        jedi.settings.cache_directory = os.path.join(
            jedi.settings.cache_directory,
            cachePrefix + jedi.__version__.replace(".", ""),
        )
    # remove jedi from path after we import it so it will not be completed
    sys.path.pop(0)
    if len(modulesToLoad) > 0:
        jedi.preload_module(*modulesToLoad.split(","))
    JediCompletion().watch()
github autocomplete-python / autocomplete-python / lib / jedi / evaluate / param.py View on Github external
def _split(self):
        if isinstance(self.argument_node, (tuple, list)):
            for el in self.argument_node:
                yield 0, el
        else:
            if not (tree.is_node(self.argument_node, 'arglist') or (
                    # in python 3.5 **arg is an argument, not arglist
                    (tree.is_node(self.argument_node, 'argument') and
                     self.argument_node.children[0] in ('*', '**')))):
                yield 0, self.argument_node
                return

            iterator = iter(self.argument_node.children)
            for child in iterator:
                if child == ',':
                    continue
                elif child in ('*', '**'):
                    yield len(child.value), next(iterator)
                elif tree.is_node(child, 'argument') and \
                        child.children[0] in ('*', '**'):
                    assert len(child.children) == 2
                    yield len(child.children[0].value), child.children[1]
github srusskih / SublimeJEDI / jedi / evaluate / param.py View on Github external
def _split(self):
        if isinstance(self.argument_node, (tuple, list)):
            for el in self.argument_node:
                yield 0, el
        else:
            if not pr.is_node(self.argument_node, 'arglist'):
                yield 0, self.argument_node
                return

            iterator = iter(self.argument_node.children)
            for child in iterator:
                if child == ',':
                    continue
                elif child in ('*', '**'):
                    yield len(child.value), next(iterator)
                else:
                    yield 0, child
github autocomplete-python / autocomplete-python / lib / jedi / evaluate / param.py View on Github external
def _split(self):
        if isinstance(self.argument_node, (tuple, list)):
            for el in self.argument_node:
                yield 0, el
        else:
            if not (tree.is_node(self.argument_node, 'arglist') or (
                    # in python 3.5 **arg is an argument, not arglist
                    (tree.is_node(self.argument_node, 'argument') and
                     self.argument_node.children[0] in ('*', '**')))):
                yield 0, self.argument_node
                return

            iterator = iter(self.argument_node.children)
            for child in iterator:
                if child == ',':
                    continue
                elif child in ('*', '**'):
                    yield len(child.value), next(iterator)
                elif tree.is_node(child, 'argument') and \
                        child.children[0] in ('*', '**'):
                    assert len(child.children) == 2
                    yield len(child.children[0].value), child.children[1]
                else:
                    yield 0, child
github JulianEberius / SublimePythonIDE / server / lib / python_all / jedi / evaluate / __init__.py View on Github external
    @memoize_default(default=[], evaluator_is_first_arg=True)
    @recursion.recursion_decorator
    @debug.increase_indent
    def eval_statement(self, stmt, seek_name=None):
        """
        The starting point of the completion. A statement always owns a call
        list, which are the calls, that a statement does. In case multiple
        names are defined in the statement, `seek_name` returns the result for
        this name.

        :param stmt: A `tree.ExprStmt`.
        """
        debug.dbg('eval_statement %s (%s)', stmt, seek_name)
        types = self.eval_element(stmt.get_rhs())

        if seek_name:
            types = finder.check_tuple_assignments(types, seek_name)

        first_operation = stmt.first_operation()
        if first_operation not in ('=', None) and not isinstance(stmt, er.InstanceElement):  # TODO don't check for this.
            # `=` is always the last character in aug assignments -> -1
            operator = copy.copy(first_operation)
            operator.value = operator.value[:-1]
            name = str(stmt.get_defined_names()[0])
            parent = self.wrap(stmt.get_parent_scope())
            left = self.find_types(parent, name, stmt.start_pos, search_global=True)
            if isinstance(stmt.get_parent_until(tree.ForStmt), tree.ForStmt):
                # Iterate through result and add the values, that's possible
                # only in for loops without clutter, because they are
github srusskih / SublimeJEDI / dependencies / jedi / inference / value / function.py View on Github external
# If there are annotations, prefer them over anything else.
                # This will make it faster.
                return value_set
            value_set |= docstrings.infer_return_types(self._value)
            returns = funcdef.iter_return_stmts()

        for r in returns:
            if check_yields:
                value_set |= ValueSet.from_sets(
                    lazy_value.infer()
                    for lazy_value in self._get_yield_lazy_value(r)
                )
            else:
                check = flow_analysis.reachability_check(self, funcdef, r)
                if check is flow_analysis.UNREACHABLE:
                    debug.dbg('Return unreachable: %s', r)
                else:
                    try:
                        children = r.children
                    except AttributeError:
                        ctx = compiled.builtin_from_name(self.inference_state, u'None')
                        value_set |= ValueSet([ctx])
                    else:
                        value_set |= self.infer_node(children[1])
                if check is flow_analysis.REACHABLE:
                    debug.dbg('Return reachable: %s', r)
                    break
        return value_set