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


Python ast.Eq方法代码示例

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


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

示例1: test_MutateAST_visit_compare

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def test_MutateAST_visit_compare(idx, mut_op, lineno, compare_file, compare_expected_locs):
    """Test mutation of the == to != in the compare op."""
    tree = Genome(compare_file).ast

    # apply the mutation to the original tree copy
    testing_tree = deepcopy(tree)
    mutated_tree = MutateAST(target_idx=compare_expected_locs[idx], mutation=mut_op).visit(
        testing_tree
    )

    # revisit in read-only mode to gather the locations of the new nodes
    mast = MutateAST(readonly=True)
    mast.visit(mutated_tree)

    assert len(mast.locs) == 3

    # check that the lineno marked for mutation is changed, otherwise original ops should
    # still be present without modification
    for loc in mast.locs:
        if loc.lineno == lineno and loc.col_offset == 11:
            assert loc.op_type == mut_op
        else:
            assert loc.op_type in {ast.Eq, ast.Is, ast.In}  # based on compare_file fixture 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:25,代码来源:test_transformers.py

示例2: visit_Compare

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def visit_Compare(self, node):
        node.obj = bool()
        for n in [node.left] + node.comparators:
            self.visit(n)
        op, arg = node.ops[0], node.comparators[0]
# #         node.expr.target = self.getObj(arg)
# #         arg.target = self.getObj(node.expr)
        # detect specialized case for the test
        if isinstance(op, ast.Eq) and isinstance(node.left, ast.Name):
            # check wether it can be a case
            val = arg.obj
            if isinstance(val, bool):
                val = int(val)  # cast bool to int first
            if isinstance(val, (EnumItemType, int)):
                node.case = (node.left, val)
            # check whether it can be part of an edge check
            n = node.left.id
            if n in self.tree.sigdict:
                sig = self.tree.sigdict[n]
                v = self.getValue(arg)
                if v is not None:
                    if v == 0:
                        node.edge = sig.negedge
                    elif v == 1:
                        node.edge = sig.posedge 
开发者ID:myhdl,项目名称:myhdl,代码行数:27,代码来源:_analyze.py

示例3: comp_op_rewrite

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def comp_op_rewrite(op: t.Union[Tokenizer, t.List[Tokenizer]]):
    """
    ('<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not')
    """
    if isinstance(op, list):
        op = tuple(map(lambda it: it.value, op))
    else:
        op = op.value

    return {
        '<': ast.Lt,
        '>': ast.Gt,
        '==': ast.Eq,
        '>=': ast.GtE,
        '<=': ast.LtE,
        '<>': lambda: raise_exp(NotImplemented),
        '!=': ast.NotEq,
        'in': ast.In,
        ('is', ): ast.Is,
        ('is', 'not'): ast.IsNot,
        ('not', 'in'): ast.NotIn,
    }[op]() 
开发者ID:Xython,项目名称:YAPyPy,代码行数:24,代码来源:helper.py

示例4: verify_ast

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def verify_ast(expr, variables_and_values):
  """Verifies that |expr| is of the form
  expr ::= expr ( "or" | "and" ) expr
         | identifier "==" ( string | int )
  Also collects the variable identifiers and string/int values in the dict
  |variables_and_values|, in the form {'var': set([val1, val2, ...]), ...}.
  """
  assert isinstance(expr, (ast.BoolOp, ast.Compare))
  if isinstance(expr, ast.BoolOp):
    assert isinstance(expr.op, (ast.And, ast.Or))
    for subexpr in expr.values:
      verify_ast(subexpr, variables_and_values)
  else:
    assert isinstance(expr.left.ctx, ast.Load)
    assert len(expr.ops) == 1
    assert isinstance(expr.ops[0], ast.Eq)
    var_values = variables_and_values.setdefault(expr.left.id, set())
    rhs = expr.comparators[0]
    assert isinstance(rhs, (ast.Str, ast.Num))
    var_values.add(rhs.n if isinstance(rhs, ast.Num) else rhs.s) 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:isolate_format.py

示例5: cmpop

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def cmpop(self, op):
    if isinstance(op, ast.Eq):
      return Operator.eq
    elif isinstance(op, ast.NotEq):
      return Operator.ne
    elif isinstance(op, ast.Lt):
      return Operator.lt
    elif isinstance(op, ast.LtE):
      return Operator.le
    elif isinstance(op, ast.Gt):
      return Operator.gt
    elif isinstance(op, ast.GtE):
      return Operator.ge
    else:
      raise Exception('Unexpected CmpOp (%s)'%(op.__class__))

  #Parses a function call (AST Call) 
开发者ID:undefx,项目名称:vecpy,代码行数:19,代码来源:parser.py

示例6: gen_compare

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def gen_compare(self, condition, yes_block, no_block):
        # print(dir(c), c.ops, c.comparators)
        # TODO: chained operators! ( 'a < b < c < d' )
        assert len(condition.ops) == len(condition.comparators)
        assert len(condition.ops) == 1
        op_map = {
            ast.Gt: ">",
            ast.GtE: ">=",
            ast.Lt: "<",
            ast.LtE: "<=",
            ast.Eq: "==",
            ast.NotEq: "!=",
        }

        a = self.gen_expr(condition.left)
        op = op_map[type(condition.ops[0])]
        b = self.gen_expr(condition.comparators[0])
        if a.ty is not b.ty:
            self.error(condition, "Type mismatch, types must be the same.")

        self.emit(ir.CJump(a, op, b, yes_block, no_block)) 
开发者ID:windelbouwman,项目名称:ppci,代码行数:23,代码来源:python2ir.py

示例7: visit_Assert

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def visit_Assert(self, node):
        if is_binary_comparison(node):
            if is_comparison_type(node, ast.Eq):
                return make_call_node(node, assert_equal.__name__)
            elif is_comparison_type(node, ast.NotEq):
                return make_call_node(node, assert_not_equal.__name__)
            elif is_comparison_type(node, ast.In):
                return make_call_node(node, assert_in.__name__)
            elif is_comparison_type(node, ast.NotIn):
                return make_call_node(node, assert_not_in.__name__)
            elif is_comparison_type(node, ast.Is):
                return make_call_node(node, assert_is.__name__)
            elif is_comparison_type(node, ast.IsNot):
                return make_call_node(node, assert_is_not.__name__)
            elif is_comparison_type(node, ast.Lt):
                return make_call_node(node, assert_less_than.__name__)
            elif is_comparison_type(node, ast.LtE):
                return make_call_node(node, assert_less_than_equal_to.__name__)
            elif is_comparison_type(node, ast.Gt):
                return make_call_node(node, assert_greater_than.__name__)
            elif is_comparison_type(node, ast.GtE):
                return make_call_node(node, assert_greater_than_equal_to.__name__)

        return node 
开发者ID:darrenburns,项目名称:ward,代码行数:26,代码来源:rewrite.py

示例8: _check_compares

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def _check_compares(self, node: ast.Compare) -> None:
        is_all_equals = all(isinstance(op, ast.Eq) for op in node.ops)
        is_all_notequals = all(isinstance(op, ast.NotEq) for op in node.ops)
        can_be_longer = is_all_notequals or is_all_equals

        threshold = constants.MAX_COMPARES
        if can_be_longer:
            threshold += 1

        if len(node.ops) > threshold:
            self.add_violation(
                complexity.TooLongCompareViolation(
                    node,
                    text=str(len(node.ops)),
                    baseline=threshold,
                ),
            ) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:19,代码来源:counts.py

示例9: compare_expected_locs

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def compare_expected_locs():
    """The compare expected locations based on the fixture"""
    # Py 3.7
    if sys.version_info < (3, 8):
        return [
            LocIndex(ast_class="Compare", lineno=2, col_offset=11, op_type=ast.Eq),
            LocIndex(ast_class="CompareIs", lineno=5, col_offset=11, op_type=ast.Is),
            LocIndex(ast_class="CompareIn", lineno=8, col_offset=11, op_type=ast.In),
        ]
    # Py 3.8
    return [
        LocIndex(
            ast_class="Compare",
            lineno=2,
            col_offset=11,
            op_type=ast.Eq,
            end_lineno=2,
            end_col_offset=17,
        ),
        LocIndex(
            ast_class="CompareIs",
            lineno=5,
            col_offset=11,
            op_type=ast.Is,
            end_lineno=5,
            end_col_offset=17,
        ),
        LocIndex(
            ast_class="CompareIn",
            lineno=8,
            col_offset=11,
            op_type=ast.In,
            end_lineno=8,
            end_col_offset=17,
        ),
    ]


####################################################################################################
# TRANSFORMERS: IF FIXTURES
#################################################################################################### 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:43,代码来源:conftest.py

示例10: _has_eq_compare

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def _has_eq_compare(node):
    return len(node.ops) == 1 and isinstance(node.ops[0], ast.Eq) 
开发者ID:devmanorg,项目名称:fiasko_bro,代码行数:4,代码来源:ast_nodes_validators.py

示例11: _is_compared_with_zero

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def _is_compared_with_zero(node):
    return (
        isinstance(node.ops[0], (ast.Gt, ast.Eq))
        and isinstance(node.comparators[0], ast.Num)
        and node.comparators[0].n == 0
    ) 
开发者ID:devmanorg,项目名称:fiasko_bro,代码行数:8,代码来源:ast_nodes_validators.py

示例12: visit_Assign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def visit_Assign(self, node, **kwargs):
        cmpr = ast.Compare(ops=[ast.Eq()], left=node.targets[0],
                           comparators=[node.value])
        return self.visit(cmpr) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:pytables.py

示例13: translate_In

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def translate_In(self, op):
        return ast.Eq() if isinstance(op, ast.In) else op 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:pytables.py

示例14: compare_ast_to_ir2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [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

示例15: _eq

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Eq [as 别名]
def _eq(test: ast.Compare, n: int) -> bool:
        return (
            isinstance(test.ops[0], ast.Eq) and
            isinstance(test.comparators[0], ast.Num) and
            test.comparators[0].n == n
        ) 
开发者ID:asottile,项目名称:pyupgrade,代码行数:8,代码来源:pyupgrade.py


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