當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。