Пример #1
0
    def _does_scope_break_immediately(self, scope, name_list_scope):
        """
        In comparison to everthing else, if/while/etc doesn't break directly,
        because there are multiple different places in which a variable can be
        defined.
        """
        if isinstance(scope, pr.Flow) \
                or isinstance(scope, pr.KeywordStatement) and scope.name == 'global':

            # Check for `if foo is not None`, because Jedi is not interested in
            # None values, so this is the only branch we actually care about.
            # ATM it carries the same issue as the isinstance checks. It
            # doesn't work with instance variables (self.foo).
            if isinstance(scope, pr.Flow) and scope.command in ('if', 'while'):
                try:
                    expression_list = scope.inputs[0].expression_list()
                except IndexError:
                    pass
                else:
                    p = precedence.create_precedence(expression_list)
                    if (isinstance(p, precedence.Precedence)
                            and p.operator.string == 'is not'
                            and p.right.get_code() == 'None'
                            and p.left.get_code() == unicode(self.name_str)):
                        return True

            if isinstance(name_list_scope, er.Class):
                name_list_scope = name_list_scope.base
            return scope == name_list_scope
        else:
            return True
Пример #2
0
    def _does_scope_break_immediately(self, scope, name_list_scope):
        """
        In comparison to everthing else, if/while/etc doesn't break directly,
        because there are multiple different places in which a variable can be
        defined.
        """
        if isinstance(scope, pr.Flow) \
                or isinstance(scope, pr.KeywordStatement) and scope.name == 'global':

            # Check for `if foo is not None`, because Jedi is not interested in
            # None values, so this is the only branch we actually care about.
            # ATM it carries the same issue as the isinstance checks. It
            # doesn't work with instance variables (self.foo).
            if isinstance(scope, pr.Flow) and scope.command in ('if', 'while'):
                try:
                    expression_list = scope.inputs[0].expression_list()
                except IndexError:
                    pass
                else:
                    p = precedence.create_precedence(expression_list)
                    if (isinstance(p, precedence.Precedence)
                            and p.operator.string == 'is not'
                            and p.right.get_code() == 'None'
                            and p.left.get_code() == unicode(self.name_str)):
                        return True

            if isinstance(name_list_scope, er.Class):
                name_list_scope = name_list_scope.base
            return scope == name_list_scope
        else:
            return True
Пример #3
0
 def eval_expression_list(self, expression_list):
     """
     `expression_list` can be either `pr.Array` or `list of list`.
     It is used to evaluate a two dimensional object, that has calls, arrays and
     operators in it.
     """
     debug.dbg('eval_expression_list: %s', expression_list)
     p = precedence.create_precedence(expression_list)
     return self.process_precedence_element(p) or []
Пример #4
0
 def eval_expression_list(self, expression_list):
     """
     `expression_list` can be either `pr.Array` or `list of list`.
     It is used to evaluate a two dimensional object, that has calls, arrays and
     operators in it.
     """
     debug.dbg('eval_expression_list: %s', expression_list)
     p = precedence.create_precedence(expression_list)
     return precedence.process_precedence_element(self, p) or []
Пример #5
0
def parse_tree(statement_string, is_slice=False):
    p = Parser(u(statement_string), no_docstr=True)
    stmt = p.module.statements[0]
    if is_slice:
        # get the part of the execution that is the slice
        stmt = stmt.expression_list()[0].execution[0]
    iterable = stmt.expression_list()
    pr = precedence.create_precedence(iterable)
    if isinstance(pr, precedence.Precedence):
        return pr.parse_tree(strip_literals=True)
    else:
        try:
            return pr.value  # Literal
        except AttributeError:
            return pr
Пример #6
0
def create_indexes_or_slices(evaluator, index_array):
    if not index_array:
        return ()

    # Just take the first part of the "array", because this is Python stdlib
    # behavior. Numpy et al. perform differently, but Jedi won't understand
    # that anyway.
    expression_list = index_array[0].expression_list()
    prec = precedence.create_precedence(expression_list)

    # check for slices
    if isinstance(prec, precedence.Precedence) and prec.operator == ':':
        start = prec.left
        if isinstance(start, precedence.Precedence) and start.operator == ':':
            stop = start.right
            start = start.left
            step = prec.right
        else:
            stop = prec.right
            step = None
        return (Slice(evaluator, start, stop, step), )
    else:
        return tuple(evaluator.process_precedence_element(prec))
Пример #7
0
def create_indexes_or_slices(evaluator, index_array):
    if not index_array:
        return ()

    # Just take the first part of the "array", because this is Python stdlib
    # behavior. Numpy et al. perform differently, but Jedi won't understand
    # that anyway.
    expression_list = index_array[0].expression_list()
    prec = precedence.create_precedence(expression_list)

    # check for slices
    if isinstance(prec, precedence.Precedence) and prec.operator == ':':
        start = prec.left
        if isinstance(start, precedence.Precedence) and start.operator == ':':
            stop = start.right
            start = start.left
            step = prec.right
        else:
            stop = prec.right
            step = None
        return (Slice(evaluator, start, stop, step),)
    else:
        return tuple(evaluator.process_precedence_element(prec))