Example #1
0
    def execute(self, obj, arguments=(), trailer=None):
        if not isinstance(arguments, param.Arguments):
            arguments = param.Arguments(self, arguments, trailer)

        if self.is_analysis:
            arguments.eval_all()

        if obj.isinstance(er.Function):
            obj = obj.get_decorated_func()

        debug.dbg('execute: %s %s', obj, arguments)
        try:
            # Some stdlib functions like super(), namedtuple(), etc. have been
            # hard-coded in Jedi to support them.
            return stdlib.execute(self, obj, arguments)
        except stdlib.NotInStdLib:
            pass

        try:
            func = obj.py__call__
        except AttributeError:
            debug.warning("no execution possible %s", obj)
            return set()
        else:
            types = func(arguments)
            debug.dbg('execute result: %s in %s', types, obj)
            return types
Example #2
0
def _check_isinstance_type(evaluator, element, search_name):
    try:
        assert element.type == 'power'
        # this might be removed if we analyze and, etc
        assert len(element.children) == 2
        first, trailer = element.children
        assert isinstance(first, pr.Name) and first.value == 'isinstance'
        assert trailer.type == 'trailer' and trailer.children[0] == '('
        assert len(trailer.children) == 3

        # arglist stuff
        arglist = trailer.children[1]
        args = param.Arguments(evaluator, arglist, trailer)
        lst = list(args.unpack())
        # Disallow keyword arguments
        assert len(lst) == 2 and lst[0][0] is None and lst[1][0] is None
        name = lst[0][1][0]  # first argument, values, first value
        # Do a simple get_code comparison. They should just have the same code,
        # and everything will be all right.
        classes = lst[1][1][0]
        call = helpers.call_of_name(search_name)
        assert name.get_code() == call.get_code()
    except AssertionError:
        return []

    result = []
    for typ in evaluator.eval_element(classes):
        for typ in (typ.values()
                    if isinstance(typ, iterable.Array) else [typ]):
            result += evaluator.execute(typ)
    return result
 def py__bases__(self, evaluator):
     arglist = self.base.get_super_arglist()
     if arglist:
         args = param.Arguments(self._evaluator, arglist)
         return list(chain.from_iterable(args.eval_args()))
     else:
         return [compiled.object_obj]
Example #4
0
def _check_isinstance_type(evaluator, element, search_name):
    try:
        assert element.type in ('power', 'atom_expr')
        # this might be removed if we analyze and, etc
        assert len(element.children) == 2
        first, trailer = element.children
        assert isinstance(first, tree.Name) and first.value == 'isinstance'
        assert trailer.type == 'trailer' and trailer.children[0] == '('
        assert len(trailer.children) == 3

        # arglist stuff
        arglist = trailer.children[1]
        args = param.Arguments(evaluator, arglist, trailer)
        lst = list(args.unpack())
        # Disallow keyword arguments
        assert len(lst) == 2 and lst[0][0] is None and lst[1][0] is None
        name = lst[0][1][0]  # first argument, values, first value
        # Do a simple get_code comparison. They should just have the same code,
        # and everything will be all right.
        classes = lst[1][1][0]
        call = helpers.call_of_leaf(search_name)
        assert name.get_code(normalized=True) == call.get_code(normalized=True)
    except AssertionError:
        return set()

    result = set()
    for cls_or_tup in evaluator.eval_element(classes):
        if isinstance(cls_or_tup,
                      iterable.Array) and cls_or_tup.type == 'tuple':
            for typ in unite(cls_or_tup.py__iter__()):
                result |= evaluator.execute(typ)
        else:
            result |= evaluator.execute(cls_or_tup)
    return result
Example #5
0
def check_array_instances(evaluator, instance):
    """Used for set() and list() instances."""
    if not settings.dynamic_array_additions:
        return instance.var_args

    ai = _ArrayInstance(evaluator, instance)
    from jedi.evaluate import param
    return param.Arguments(evaluator, [AlreadyEvaluated([ai])])
Example #6
0
def builtins_reversed(evaluator, sequences, obj):
    # Unpack the iterator values
    objects = tuple(iterable.get_iterator_types(sequences))
    rev = [iterable.AlreadyEvaluated([o]) for o in reversed(objects)]
    # Repack iterator values and then run it the normal way. This is
    # necessary, because `reversed` is a function and autocompletion
    # would fail in certain cases like `reversed(x).__iter__` if we
    # just returned the result directly.
    rev = iterable.AlreadyEvaluated(
        [iterable.FakeSequence(evaluator, rev, 'list')])
    return [er.Instance(evaluator, obj, param.Arguments(evaluator, [rev]))]
Example #7
0
def builtins_reversed(evaluator, sequences, obj, arguments):
    # While we could do without this variable (just by using sequences), we
    # want static analysis to work well. Therefore we need to generated the
    # values again.
    first_arg = next(arguments.as_tuple())[0]
    ordered = list(iterable.py__iter__(evaluator, sequences, first_arg))

    rev = [iterable.AlreadyEvaluated(o) for o in reversed(ordered)]
    # Repack iterator values and then run it the normal way. This is
    # necessary, because `reversed` is a function and autocompletion
    # would fail in certain cases like `reversed(x).__iter__` if we
    # just returned the result directly.
    rev = iterable.AlreadyEvaluated(
        [iterable.FakeSequence(evaluator, rev, 'list')]
    )
    return set([er.Instance(evaluator, obj, param.Arguments(evaluator, [rev]))])