当前位置: 首页>>代码示例>>Python>>正文


Python ast.Set方法代码示例

本文整理汇总了Python中ast.Set方法的典型用法代码示例。如果您正苦于以下问题:Python ast.Set方法的具体用法?Python ast.Set怎么用?Python ast.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ast的用法示例。


在下文中一共展示了ast.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: number_literal_expression_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def number_literal_expression_ast_to_ir2(ast_node: ast.Num,
                                         compilation_context: CompilationContext,
                                         in_match_pattern: bool,
                                         check_var_reference: Callable[[ast.Name], None],
                                         match_lambda_argument_names: Set[str],
                                         positive: bool):
    n = ast_node.n
    if isinstance(n, float):
        raise CompilationError(compilation_context, ast_node, 'Floating-point values are not supported.')
    if isinstance(n, complex):
        raise CompilationError(compilation_context, ast_node, 'Complex values are not supported.')
    assert isinstance(n, int)
    if not positive:
        n = -n
    if n <= -2**63:
        raise CompilationError(compilation_context, ast_node,
                               'int value out of bounds: values lower than -2^63+1 are not supported.')
    if n >= 2**63:
        raise CompilationError(compilation_context, ast_node,
                               'int value out of bounds: values greater than 2^63-1 are not supported.')
    return ir2.IntLiteral(value=n) 
开发者ID:google,项目名称:tmppy,代码行数:23,代码来源:_ast_to_ir2.py

示例2: not_expression_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def not_expression_ast_to_ir2(ast_node: ast.UnaryOp,
                              compilation_context: CompilationContext,
                              in_match_pattern: bool,
                              check_var_reference: Callable[[ast.Name], None],
                              match_lambda_argument_names: Set[str],
                              current_stmt_line: int):
    assert isinstance(ast_node.op, ast.Not)

    if in_match_pattern:
        raise CompilationError(compilation_context, ast_node,
                               'The "not" operator is not allowed in match patterns')

    expr = expression_ast_to_ir2(ast_node.operand,
                                 compilation_context,
                                 in_match_pattern,
                                 check_var_reference,
                                 match_lambda_argument_names,
                                 current_stmt_line)

    if expr.expr_type != ir2.BoolType():
        raise CompilationError(compilation_context, ast_node.operand,
                               'The "not" operator is only supported for booleans, but this value has type %s.' % str(expr.expr_type))

    return ir2.NotExpr(expr=expr) 
开发者ID:google,项目名称:tmppy,代码行数:26,代码来源:_ast_to_ir2.py

示例3: unary_minus_expression_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def unary_minus_expression_ast_to_ir2(ast_node: ast.UnaryOp,
                                      compilation_context: CompilationContext,
                                      in_match_pattern: bool,
                                      check_var_reference: Callable[[ast.Name], None],
                                      match_lambda_argument_names: Set[str],
                                      current_stmt_line: int):
    assert isinstance(ast_node.op, ast.USub)

    if in_match_pattern:
        raise CompilationError(compilation_context, ast_node,
                               'The "-" operator is not allowed in match patterns')

    expr = expression_ast_to_ir2(ast_node.operand,
                                 compilation_context,
                                 in_match_pattern,
                                 check_var_reference,
                                 match_lambda_argument_names,
                                 current_stmt_line)

    if expr.expr_type != ir2.IntType():
        raise CompilationError(compilation_context, ast_node.operand,
                               'The "-" operator is only supported for ints, but this value has type %s.' % str(expr.expr_type))

    return ir2.IntUnaryMinusExpr(expr=expr) 
开发者ID:google,项目名称:tmppy,代码行数:26,代码来源:_ast_to_ir2.py

示例4: _extract_single_type_expr_arg

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def _extract_single_type_expr_arg(ast_node: ast.Call,
                                  called_fun_name: str,
                                  compilation_context: CompilationContext,
                                  in_match_pattern: bool,
                                  check_var_reference: Callable[[ast.Name], None],
                                  match_lambda_argument_names: Set[str],
                                  current_stmt_line: int):
    if ast_node.keywords:
        raise CompilationError(compilation_context, ast_node.keywords[0].value,
                               'Keyword arguments are not supported in %s()' % called_fun_name)

    if len(ast_node.args) != 1:
        raise CompilationError(compilation_context, ast_node, '%s() takes 1 argument. Got: %s' % (called_fun_name, len(ast_node.args)))
    [arg] = ast_node.args

    arg_ir = expression_ast_to_ir2(arg,
                                   compilation_context,
                                   in_match_pattern,
                                   check_var_reference,
                                   match_lambda_argument_names,
                                   current_stmt_line)
    if arg_ir.expr_type != ir2.TypeType():
        raise CompilationError(compilation_context, arg, 'The argument passed to %s() should have type Type, but was: %s' % (called_fun_name, str(arg_ir.expr_type)))
    return arg_ir 
开发者ID:google,项目名称:tmppy,代码行数:26,代码来源:_ast_to_ir2.py

示例5: _make_function

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def _make_function(instr, queue, stack, body, context):
    """
    Set a make_function_context, then push onto the stack.
    """
    assert stack, "Empty stack before MAKE_FUNCTION."
    prev = stack[-1]
    expect(prev, instrs.LOAD_CONST, "before MAKE_FUNCTION")

    stack.append(instr)

    if is_lambda_name(prev.arg):
        return

    return context.update(
        make_function_context=MakeFunctionContext(
            closure=isinstance(instr, instrs.MAKE_CLOSURE),
        )
    ) 
开发者ID:llllllllll,项目名称:codetransformer,代码行数:20,代码来源:_343.py

示例6: _resolve_constant

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def _resolve_constant(node):
    if isinstance(node, str_types):
        return node.s
    elif isinstance(node, ast.Num):
        return node.n
    elif isinstance(node, ast.List):
        return [_resolve_constant(e) for e in node.elts]
    elif isinstance(node, ast.Set):
        return set(_resolve_constant(e) for e in node.elts)
    elif isinstance(node, ast.Tuple):
        return tuple(_resolve_constant(e) for e in node.elts)
    elif isinstance(node, ast.Dict):
        res = {}
        for k, v in zip(node.keys, node.values):
            res[_resolve_constant(k)] = _resolve_constant(v)
        return res
    else:
        raise NotConstant()


# This parses .py files for simple variable assignment
# I'm making an assumption that the file will not contain any complicated code,
# or features that would be version-dependent. Since Horizon aims for
# compatibility with common systems, this should be a fair assumption. 
开发者ID:HewlettPackard,项目名称:reconbf,代码行数:26,代码来源:test_horizon.py

示例7: _almost_swapped

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def _almost_swapped(self, assigns: Sequence[ast.Assign]) -> None:
        previous_var: Set[Optional[str]] = set()

        for assign in assigns:
            current_var = {
                first(name_nodes.flat_variable_names([assign])),
                first(name_nodes.get_variables_from_node(assign.value)),
            }

            if not all(map(bool, current_var)):
                previous_var.clear()
                continue

            if current_var == previous_var:
                self.add_violation(AlmostSwappedViolation(assign))

            if len(previous_var & current_var) == 1:
                current_var ^= previous_var

            previous_var = current_var 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:22,代码来源:statements.py

示例8: compare_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def compare_ast_to_ir2(ast_node: ast.Compare,
                       compilation_context: CompilationContext,
                       in_match_pattern: bool,
                       check_var_reference: Callable[[ast.Name], None],
                       match_lambda_argument_names: Set[str],
                       current_stmt_line: int):
    if len(ast_node.ops) != 1 or len(ast_node.comparators) != 1:
        raise CompilationError(compilation_context, ast_node, 'Comparison not supported.')  # pragma: no cover

    if in_match_pattern:
        raise CompilationError(compilation_context, ast_node,
                               'Comparisons are not allowed in match patterns')

    lhs = ast_node.left
    op = ast_node.ops[0]
    rhs = ast_node.comparators[0]

    if isinstance(op, ast.Eq):
        return eq_ast_to_ir2(lhs, rhs, compilation_context, in_match_pattern, check_var_reference, current_stmt_line)
    elif isinstance(op, ast.NotEq):
        return not_eq_ast_to_ir2(lhs, rhs, compilation_context, in_match_pattern, check_var_reference, current_stmt_line)
    elif isinstance(op, ast.In):
        return in_ast_to_ir2(lhs, rhs, compilation_context, in_match_pattern, check_var_reference, current_stmt_line)
    elif isinstance(op, ast.Lt):
        return int_comparison_ast_to_ir2(lhs, rhs, '<', compilation_context, in_match_pattern, check_var_reference, current_stmt_line)
    elif isinstance(op, ast.LtE):
        return int_comparison_ast_to_ir2(lhs, rhs, '<=', compilation_context, in_match_pattern, check_var_reference, current_stmt_line)
    elif isinstance(op, ast.Gt):
        return int_comparison_ast_to_ir2(lhs, rhs, '>', compilation_context, in_match_pattern, check_var_reference, current_stmt_line)
    elif isinstance(op, ast.GtE):
        return int_comparison_ast_to_ir2(lhs, rhs, '>=', compilation_context, in_match_pattern, check_var_reference, current_stmt_line)
    else:
        raise CompilationError(compilation_context, ast_node, 'Comparison not supported.')  # pragma: no cover 
开发者ID:google,项目名称:tmppy,代码行数:35,代码来源:_ast_to_ir2.py

示例9: attribute_expression_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def attribute_expression_ast_to_ir2(ast_node: ast.Attribute,
                                    compilation_context: CompilationContext,
                                    in_match_pattern: bool,
                                    check_var_reference: Callable[[ast.Name], None],
                                    match_lambda_argument_names: Set[str],
                                    current_stmt_line: int):
    if in_match_pattern:
        raise CompilationError(compilation_context, ast_node,
                               'Attribute access is not allowed in match patterns')

    value_expr = expression_ast_to_ir2(ast_node.value,
                                       compilation_context,
                                       in_match_pattern,
                                       check_var_reference,
                                       match_lambda_argument_names,
                                       current_stmt_line)
    if isinstance(value_expr.expr_type, ir2.TypeType):
        return ir2.AttributeAccessExpr(expr=value_expr,
                                       attribute_name=ast_node.attr,
                                       expr_type=ir2.TypeType())
    elif isinstance(value_expr.expr_type, ir2.CustomType):
        for arg in value_expr.expr_type.arg_types:
            if arg.name == ast_node.attr:
                return ir2.AttributeAccessExpr(expr=value_expr,
                                               attribute_name=ast_node.attr,
                                               expr_type=arg.expr_type)
        else:
            lookup_result = compilation_context.get_type_symbol_definition(value_expr.expr_type.name)
            assert lookup_result
            raise CompilationError(compilation_context, ast_node.value,
                                   'Values of type "%s" don\'t have the attribute "%s". The available attributes for this type are: {"%s"}.' % (
                                       str(value_expr.expr_type), ast_node.attr, '", "'.join(sorted(arg.name
                                                                                               for arg in value_expr.expr_type.arg_types))),
                                   notes=[(lookup_result.ast_node, '%s was defined here.' % str(value_expr.expr_type))])
    else:
        raise CompilationError(compilation_context, ast_node.value,
                               'Attribute access is not supported for values of type %s.' % str(value_expr.expr_type)) 
开发者ID:google,项目名称:tmppy,代码行数:39,代码来源:_ast_to_ir2.py

示例10: and_expression_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def and_expression_ast_to_ir2(ast_node: ast.BoolOp,
                              compilation_context: CompilationContext,
                              in_match_pattern: bool,
                              check_var_reference: Callable[[ast.Name], None],
                              match_lambda_argument_names: Set[str],
                              current_stmt_line: int):
    assert isinstance(ast_node.op, ast.And)

    if in_match_pattern:
        raise CompilationError(compilation_context, ast_node,
                               'The "and" operator is not allowed in match patterns')

    if not compilation_context.current_function_name:
        raise CompilationError(compilation_context, ast_node,
                               'The "and" operator is only supported in functions, not at toplevel.')

    assert len(ast_node.values) >= 2

    exprs = []
    for expr_ast_node in ast_node.values:
        expr = expression_ast_to_ir2(expr_ast_node,
                                     compilation_context,
                                     in_match_pattern,
                                     check_var_reference,
                                     match_lambda_argument_names,
                                     current_stmt_line)
        if expr.expr_type != ir2.BoolType():
            raise CompilationError(compilation_context, expr_ast_node,
                                   'The "and" operator is only supported for booleans, but this value has type %s.' % str(expr.expr_type))
        exprs.append(expr)

    final_expr = exprs[-1]
    for expr in reversed(exprs[:-1]):
        final_expr = ir2.AndExpr(lhs=expr, rhs=final_expr)

    return final_expr 
开发者ID:google,项目名称:tmppy,代码行数:38,代码来源:_ast_to_ir2.py

示例11: int_binary_op_expression_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def int_binary_op_expression_ast_to_ir2(ast_node: ast.BinOp,
                                        op: str,
                                        compilation_context: CompilationContext,
                                        in_match_pattern: bool,
                                        check_var_reference: Callable[[ast.Name], None],
                                        match_lambda_argument_names: Set[str],
                                        current_stmt_line: int):
    lhs = expression_ast_to_ir2(ast_node.left,
                                compilation_context,
                                in_match_pattern,
                                check_var_reference,
                                match_lambda_argument_names,
                                current_stmt_line)
    rhs = expression_ast_to_ir2(ast_node.right,
                                compilation_context,
                                in_match_pattern,
                                check_var_reference,
                                match_lambda_argument_names,
                                current_stmt_line)

    if in_match_pattern:
        raise CompilationError(compilation_context, ast_node,
                               'The "%s" operator is not allowed in match patterns' % op)

    if lhs.expr_type != ir2.IntType():
        raise CompilationError(compilation_context, ast_node.left,
                               'The "%s" operator is only supported for ints, but this value has type %s.' % (op, str(lhs.expr_type)))

    if rhs.expr_type != ir2.IntType():
        raise CompilationError(compilation_context, ast_node.right,
                               'The "%s" operator is only supported for ints, but this value has type %s.' % (op, str(rhs.expr_type)))

    return ir2.IntBinaryOpExpr(lhs=lhs, rhs=rhs, op=op) 
开发者ID:google,项目名称:tmppy,代码行数:35,代码来源:_ast_to_ir2.py

示例12: add_expression_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def add_expression_ast_to_ir2(ast_node: ast.BinOp,
                              compilation_context: CompilationContext,
                              in_match_pattern: bool,
                              check_var_reference: Callable[[ast.Name], None],
                              match_lambda_argument_names: Set[str],
                              current_stmt_line: int):
    lhs = expression_ast_to_ir2(ast_node.left,
                                compilation_context,
                                in_match_pattern,
                                check_var_reference,
                                match_lambda_argument_names,
                                current_stmt_line)
    rhs = expression_ast_to_ir2(ast_node.right,
                                compilation_context,
                                in_match_pattern,
                                check_var_reference,
                                match_lambda_argument_names,
                                current_stmt_line)

    if in_match_pattern:
        raise CompilationError(compilation_context, ast_node,
                               'The "+" operator is not allowed in match patterns')

    if not isinstance(lhs.expr_type, (ir2.IntType, ir2.ListType)):
        raise CompilationError(compilation_context, ast_node.left,
                               'The "+" operator is only supported for ints and lists, but this value has type %s.' % str(lhs.expr_type))

    if not isinstance(rhs.expr_type, (ir2.IntType, ir2.ListType)):
        raise CompilationError(compilation_context, ast_node.right,
                               'The "+" operator is only supported for ints and lists, but this value has type %s.' % str(rhs.expr_type))

    if lhs.expr_type != rhs.expr_type:
        raise CompilationError(compilation_context, ast_node.left,
                               'Type mismatch: the LHS of "+" has type %s but the RHS has type %s.' % (str(lhs.expr_type), str(rhs.expr_type)))

    if lhs.expr_type == ir2.IntType():
        return ir2.IntBinaryOpExpr(lhs=lhs, rhs=rhs, op='+')
    else:
        return ir2.ListConcatExpr(lhs=lhs, rhs=rhs) 
开发者ID:google,项目名称:tmppy,代码行数:41,代码来源:_ast_to_ir2.py

示例13: name_constant_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def name_constant_ast_to_ir2(ast_node: ast.NameConstant,
                             compilation_context: CompilationContext,
                             in_match_pattern: bool,
                             check_var_reference: Callable[[ast.Name], None],
                             match_lambda_argument_names: Set[str]):
    if isinstance(ast_node.value, bool):
        return ir2.BoolLiteral(value=ast_node.value)
    else:
        raise CompilationError(compilation_context, ast_node, 'NameConstant not supported: ' + str(ast_node.value))  # pragma: no cover 
开发者ID:google,项目名称:tmppy,代码行数:11,代码来源:_ast_to_ir2.py

示例14: type_pointer_expr_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def type_pointer_expr_ast_to_ir2(ast_node: ast.Call,
                                 compilation_context: CompilationContext,
                                 in_match_pattern: bool,
                                 check_var_reference: Callable[[ast.Name], None],
                                 match_lambda_argument_names: Set[str],
                                 current_stmt_line: int):
    return ir2.PointerTypeExpr(_extract_single_type_expr_arg(ast_node,
                                                             'Type.pointer',
                                                             compilation_context,
                                                             in_match_pattern,
                                                             check_var_reference,
                                                             match_lambda_argument_names,
                                                             current_stmt_line)) 
开发者ID:google,项目名称:tmppy,代码行数:15,代码来源:_ast_to_ir2.py

示例15: type_reference_expr_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Set [as 别名]
def type_reference_expr_ast_to_ir2(ast_node: ast.Call,
                                   compilation_context: CompilationContext,
                                   in_match_pattern: bool,
                                   check_var_reference: Callable[[ast.Name], None],
                                   match_lambda_argument_names: Set[str],
                                   current_stmt_line: int):
    return ir2.ReferenceTypeExpr(_extract_single_type_expr_arg(ast_node,
                                                               'Type.reference',
                                                               compilation_context,
                                                               in_match_pattern,
                                                               check_var_reference,
                                                               match_lambda_argument_names,
                                                               current_stmt_line)) 
开发者ID:google,项目名称:tmppy,代码行数:15,代码来源:_ast_to_ir2.py


注:本文中的ast.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。