How to use the jedi.parser.tree.is_node function in jedi

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 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 srusskih / SublimeJEDI / jedi / evaluate / representation.py View on Github external
if self_name is None:
                continue

            if sub.name.value == '__init__' and not self.is_generated:
                # ``__init__`` is special because the params need are injected
                # this way. Therefore an execution is necessary.
                if not sub.get_decorators():
                    # __init__ decorators should generally just be ignored,
                    # because to follow them and their self variables is too
                    # complicated.
                    sub = self._get_method_execution(sub)
            for name_list in sub.names_dict.values():
                for name in name_list:
                    if name.value == self_name and name.prev_sibling() is None:
                        trailer = name.next_sibling()
                        if tree.is_node(trailer, 'trailer') \
                                and len(trailer.children) == 2 \
                                and trailer.children[0] == '.':
                            name = trailer.children[1]  # After dot.
                            if name.is_definition():
                                arr = names.setdefault(name.value, [])
                                arr.append(get_instance_el(self._evaluator, self, name))
        return names
github snakeleon / YouCompleteMe-x64 / third_party / ycmd / third_party / JediHTTP / vendor / jedi / jedi / evaluate / precedence.py View on Github external
def calculate_children(evaluator, children):
    """
    Calculate a list of children with operators.
    """
    iterator = iter(children)
    types = evaluator.eval_element(next(iterator))
    for operator in iterator:
        right = next(iterator)
        if tree.is_node(operator, 'comp_op'):  # not in / is not
            operator = ' '.join(str(c.value) for c in operator.children)

        # handle lazy evaluation of and/or here.
        if operator in ('and', 'or'):
            left_bools = set([left.py__bool__() for left in types])
            if left_bools == set([True]):
                if operator == 'and':
                    types = evaluator.eval_element(right)
            elif left_bools == set([False]):
                if operator != 'and':
                    types = evaluator.eval_element(right)
            # Otherwise continue, because of uncertainty.
        else:
            types = calculate(evaluator, types, operator,
                              evaluator.eval_element(right))
    debug.dbg('calculate_children types %s', types)
github DonJayamanne / pythonVSCode / pythonFiles / release / jedi / evaluate / iterable.py View on Github external
    @memoize_default()
    def eval_node(self):
        """
        The first part `x + 1` of the list comprehension:

            [x + 1 for x in foo]
        """
        comprehension = self._atom.children[1]
        # For nested comprehensions we need to search the last one.
        last = comprehension.children[-1]
        last_comp = comprehension.children[1]
        while True:
            if isinstance(last, tree.CompFor):
                last_comp = last
            elif not tree.is_node(last, 'comp_if'):
                break
            last = last.children[-1]

        return helpers.deep_ast_copy(comprehension.children[0], parent=last_comp)
github facebookarchive / atom-ide-ui / modules / atom-ide-debugger-python / VendorLib / vs-py-debugger / pythonFiles / preview / jedi / evaluate / iterable.py View on Github external
def create_index_types(evaluator, index):
    """
    Handles slices in subscript nodes.
    """
    if index == ':':
        # Like array[:]
        return set([Slice(evaluator, None, None, None)])
    elif tree.is_node(index, 'subscript'):  # subscript is a slice operation.
        # Like array[:3]
        result = []
        for el in index.children:
            if el == ':':
                if not result:
                    result.append(None)
            elif tree.is_node(el, 'sliceop'):
                if len(el.children) == 2:
                    result.append(el.children[1])
            else:
                result.append(el)
        result += [None] * (3 - len(result))

        return set([Slice(evaluator, *result)])

    # No slices
    return evaluator.eval_element(index)
github JulianEberius / SublimePythonIDE / server / lib / python_all / jedi / evaluate / dynamic.py View on Github external
        @memoize_default([], evaluator_is_first_arg=True)
        def get_posibilities(evaluator, module, func_name):
            try:
                names = module.used_names[func_name]
            except KeyError:
                return []

            for name in names:
                parent = name.parent
                if tree.is_node(parent, 'trailer'):
                    parent = parent.parent

                trailer = None
                if tree.is_node(parent, 'power'):
                    for t in parent.children[1:]:
                        if t == '**':
                            break
                        if t.start_pos > name.start_pos and t.children[0] == '(':
                            trailer = t
                            break
                if trailer is not None:
                    types = evaluator.goto_definition(name)

                    # We have to remove decorators, because they are not the
                    # "original" functions, this way we can easily compare.
                    # At the same time we also have to remove InstanceElements.
github autocomplete-python / autocomplete-python / lib / jedi / evaluate / sys_path.py View on Github external
def get_sys_path_powers(names):
        for name in names:
            power = name.parent.parent
            if tree.is_node(power, 'power', 'atom_expr'):
                c = power.children
                if isinstance(c[0], tree.Name) and c[0].value == 'sys' \
                        and tree.is_node(c[1], 'trailer'):
                    n = c[1].children[1]
                    if isinstance(n, tree.Name) and n.value == 'path':
                        yield name, power