Beispiel #1
0
def _eval_param(evaluator, param, scope):
    res_new = set()
    func = param.get_parent_scope()

    cls = func.parent.get_parent_until((tree.Class, tree.Function))

    from jedi.evaluate.param import ExecutedParam, Arguments
    if isinstance(cls, tree.Class) and param.position_nr == 0 \
            and not isinstance(param, ExecutedParam):
        # This is where we add self - if it has never been
        # instantiated.
        if isinstance(scope, er.InstanceElement):
            res_new.add(scope.instance)
        else:
            inst = er.Instance(evaluator,
                               evaluator.wrap(cls),
                               Arguments(evaluator, ()),
                               is_generated=True)
            res_new.add(inst)
        return res_new

    # Instances are typically faked, if the instance is not called from
    # outside. Here we check it for __init__ functions and return.
    if isinstance(func, er.InstanceElement) \
            and func.instance.is_generated and str(func.name) == '__init__':
        param = func.var.params[param.position_nr]

    # Add pep0484 and docstring knowledge.
    pep0484_hints = pep0484.follow_param(evaluator, param)
    doc_params = docstrings.follow_param(evaluator, param)
    if pep0484_hints or doc_params:
        return list(set(pep0484_hints) | set(doc_params))

    if isinstance(param, ExecutedParam):
        return res_new | param.eval(evaluator)
    else:
        # Param owns no information itself.
        res_new |= dynamic.search_params(evaluator, param)
        if not res_new:
            if param.stars:
                t = 'tuple' if param.stars == 1 else 'dict'
                typ = list(evaluator.find_types(evaluator.BUILTINS, t))[0]
                res_new = evaluator.execute(typ)
        if param.default:
            res_new |= evaluator.eval_element(param.default)
        return res_new
Beispiel #2
0
def _eval_param(evaluator, param, scope):
    res_new = []
    func = param.parent

    cls = func.parent.get_parent_until((pr.Class, pr.Function))

    from jedi.evaluate.param import ExecutedParam, Arguments
    if isinstance(cls, pr.Class) and param.position_nr == 0 \
            and not isinstance(param, ExecutedParam):
        # This is where we add self - if it has never been
        # instantiated.
        if isinstance(scope, er.InstanceElement):
            res_new.append(scope.instance)
        else:
            inst = er.Instance(evaluator, er.wrap(evaluator, cls),
                               Arguments(evaluator, ()), is_generated=True)
            res_new.append(inst)
        return res_new

    # Instances are typically faked, if the instance is not called from
    # outside. Here we check it for __init__ functions and return.
    if isinstance(func, er.InstanceElement) \
            and func.instance.is_generated and str(func.name) == '__init__':
        param = func.var.params[param.position_nr]

    # Add docstring knowledge.
    doc_params = docstrings.follow_param(evaluator, param)
    if doc_params:
        return doc_params

    if isinstance(param, ExecutedParam):
        return res_new + param.eval(evaluator)
    else:
        # Param owns no information itself.
        res_new += dynamic.search_params(evaluator, param)
        if not res_new:
            if param.stars:
                t = 'tuple' if param.stars == 1 else 'dict'
                typ = evaluator.find_types(compiled.builtin, t)[0]
                res_new = evaluator.execute(typ)
        if param.default:
            res_new += evaluator.eval_element(param.default)
        return res_new
Beispiel #3
0
def _eval_param(evaluator, param, scope):
    res_new = []
    func = param.get_parent_scope()

    cls = func.parent.get_parent_until((pr.Class, pr.Function))

    from jedi.evaluate.param import ExecutedParam, Arguments
    if isinstance(cls, pr.Class) and param.position_nr == 0 \
            and not isinstance(param, ExecutedParam):
        # This is where we add self - if it has never been
        # instantiated.
        if isinstance(scope, er.InstanceElement):
            res_new.append(scope.instance)
        else:
            inst = er.Instance(evaluator, er.wrap(evaluator, cls),
                               Arguments(evaluator, ()), is_generated=True)
            res_new.append(inst)
        return res_new

    # Instances are typically faked, if the instance is not called from
    # outside. Here we check it for __init__ functions and return.
    if isinstance(func, er.InstanceElement) \
            and func.instance.is_generated and str(func.name) == '__init__':
        param = func.var.params[param.position_nr]

    # Add docstring knowledge.
    doc_params = docstrings.follow_param(evaluator, param)
    if doc_params:
        return doc_params

    if isinstance(param, ExecutedParam):
        return res_new + param.eval(evaluator)
    else:
        # Param owns no information itself.
        res_new += dynamic.search_params(evaluator, param)
        if not res_new:
            if param.stars:
                t = 'tuple' if param.stars == 1 else 'dict'
                typ = evaluator.find_types(compiled.builtin, t)[0]
                res_new = evaluator.execute(typ)
        if param.default:
            res_new += evaluator.eval_element(param.default)
        return res_new
Beispiel #4
0
def _eval_param(evaluator, param, scope):
    res_new = set()
    func = param.get_parent_scope()

    cls = func.parent.get_parent_until((tree.Class, tree.Function))

    from jedi.evaluate.param import ExecutedParam, Arguments

    if isinstance(cls, tree.Class) and param.position_nr == 0 and not isinstance(param, ExecutedParam):
        # This is where we add self - if it has never been
        # instantiated.
        if isinstance(scope, er.InstanceElement):
            res_new.add(scope.instance)
        else:
            inst = er.Instance(evaluator, evaluator.wrap(cls), Arguments(evaluator, ()), is_generated=True)
            res_new.add(inst)
        return res_new

    # Instances are typically faked, if the instance is not called from
    # outside. Here we check it for __init__ functions and return.
    if isinstance(func, er.InstanceElement) and func.instance.is_generated and str(func.name) == "__init__":
        param = func.var.params[param.position_nr]

    # Add pep0484 and docstring knowledge.
    pep0484_hints = pep0484.follow_param(evaluator, param)
    doc_params = docstrings.follow_param(evaluator, param)
    if pep0484_hints or doc_params:
        return list(set(pep0484_hints) | set(doc_params))

    if isinstance(param, ExecutedParam):
        return res_new | param.eval(evaluator)
    else:
        # Param owns no information itself.
        res_new |= dynamic.search_params(evaluator, param)
        if not res_new:
            if param.stars:
                t = "tuple" if param.stars == 1 else "dict"
                typ = list(evaluator.find_types(evaluator.BUILTINS, t))[0]
                res_new = evaluator.execute(typ)
        if param.default:
            res_new |= evaluator.eval_element(param.default)
        return res_new