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


Python ast.NotEq方法代码示例

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


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

示例1: comp_op_rewrite

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

示例2: cmpop

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

示例3: gen_compare

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

示例4: visit_Assert

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

示例5: _check_compares

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

示例6: compare_ast_to_ir2

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

示例7: invert

# 需要导入模块: import ast [as 别名]
# 或者: from ast import NotEq [as 别名]
def invert(node):
    """
    Invert the operation in an ast node object (get its negation).

    Args:
        node: An ast node object.

    Returns:
        An ast node object containing the inverse (negation) of the input node.
    """
    inverse = {ast.Eq: ast.NotEq,
               ast.NotEq: ast.Eq,
               ast.Lt: ast.GtE,
               ast.LtE: ast.Gt,
               ast.Gt: ast.LtE,
               ast.GtE: ast.Lt,
               ast.Is: ast.IsNot,
               ast.IsNot: ast.Is,
               ast.In: ast.NotIn,
               ast.NotIn: ast.In}

    if type(node) == ast.Compare:
        op = type(node.ops[0])
        inverse_node = ast.Compare(left=node.left, ops=[inverse[op]()],
                                   comparators=node.comparators)
    elif isinstance(node, ast.BinOp) and type(node.op) in inverse:
        op = type(node.op)
        inverse_node = ast.BinOp(node.left, inverse[op](), node.right)
    elif type(node) == ast.NameConstant and node.value in [True, False]:
        inverse_node = ast.NameConstant(value=not node.value)
    else:
        inverse_node = ast.UnaryOp(op=ast.Not(), operand=node)

    return inverse_node 
开发者ID:coetaur0,项目名称:staticfg,代码行数:36,代码来源:builder.py

示例8: __init__

# 需要导入模块: import ast [as 别名]
# 或者: from ast import NotEq [as 别名]
def __init__( s, component ):
    super().__init__( component )
    s.loop_var_env = set()
    s.tmp_var_env = set()

    # opmap maps an ast operator to its RTLIR counterpart.
    s.opmap = {
      # Bool operators
      # Note: we do not support boolean operators because Python does
      # not allow overloading And and Or operators. Using them in
      # expressions might lead to inconsistent semantics.
      # ast.And    : bir.And(),       ast.Or     : bir.Or(),
      # Unary operators
      # Note: ast.Not is disallowed because it is a boolean operator
      # ast.Not    : bir.Not(),
      ast.Invert : bir.Invert(),
      ast.UAdd   : bir.UAdd(),      ast.USub   : bir.USub(),
      # Binary operators
      ast.Add    : bir.Add(),       ast.Sub    : bir.Sub(),
      ast.Mult   : bir.Mult(),      ast.Div    : bir.Div(),
      ast.Mod    : bir.Mod(),       ast.Pow    : bir.Pow(),
      ast.LShift : bir.ShiftLeft(), ast.RShift : bir.ShiftRightLogic(),
      ast.BitOr  : bir.BitOr(),     ast.BitAnd : bir.BitAnd(),
      ast.BitXor : bir.BitXor(),
      # Compare bir.bir.operators
      ast.Eq     : bir.Eq(),        ast.NotEq  : bir.NotEq(),
      ast.Lt     : bir.Lt(),        ast.LtE    : bir.LtE(),
      ast.Gt     : bir.Gt(),        ast.GtE    : bir.GtE()
    }

  # Override 
开发者ID:pymtl,项目名称:pymtl3,代码行数:33,代码来源:BehavioralRTLIRGenL2Pass.py

示例9: visit_Compare

# 需要导入模块: import ast [as 别名]
# 或者: from ast import NotEq [as 别名]
def visit_Compare(self, node: ast.Compare) -> Any:
        """Recursively visit the comparators and apply the operations on them."""
        # pylint: disable=too-many-branches
        left = self.visit(node=node.left)

        comparators = [self.visit(node=comparator) for comparator in node.comparators]

        result = None  # type: Optional[Any]
        for comparator, op in zip(comparators, node.ops):
            if isinstance(op, ast.Eq):
                comparison = left == comparator
            elif isinstance(op, ast.NotEq):
                comparison = left != comparator
            elif isinstance(op, ast.Lt):
                comparison = left < comparator
            elif isinstance(op, ast.LtE):
                comparison = left <= comparator
            elif isinstance(op, ast.Gt):
                comparison = left > comparator
            elif isinstance(op, ast.GtE):
                comparison = left >= comparator
            elif isinstance(op, ast.Is):
                comparison = left is comparator
            elif isinstance(op, ast.IsNot):
                comparison = left is not comparator
            elif isinstance(op, ast.In):
                comparison = left in comparator
            elif isinstance(op, ast.NotIn):
                comparison = left not in comparator
            else:
                raise NotImplementedError("Unhandled op of {}: {}".format(node, op))

            if result is None:
                result = comparison
            else:
                result = result and comparison

            left = comparator

        self.recomputed_values[node] = result
        return result 
开发者ID:Parquery,项目名称:icontract,代码行数:43,代码来源:_recompute.py

示例10: p_comp_op_6

# 需要导入模块: import ast [as 别名]
# 或者: from ast import NotEq [as 别名]
def p_comp_op_6(p):
    '''comp_op : NOTEQUAL'''
    #                   1
    p[0] = ast.NotEq(rule=inspect.currentframe().f_code.co_name) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:6,代码来源:hgawk_grammar.py

示例11: visit_Compare

# 需要导入模块: import ast [as 别名]
# 或者: from ast import NotEq [as 别名]
def visit_Compare (self, node):
        if len (node.comparators) > 1:
            self.emit ('(')

        left = node.left
        for index, (op, right) in enumerate (zip (node.ops, node.comparators)):
            if index:
                self.emit (' && ')

            if type (op) in (ast.In, ast.NotIn) or (self.allowOperatorOverloading and type (op) in (
                ast.Eq, ast.NotEq, ast.Lt, ast.LtE, ast.Gt, ast.GtE
            )):
                self.emit ('{} ('.format (self.filterId (

                    # Non-overloaded
                    '__in__' if type (op) == ast.In else
                    '!__in__' if type (op) == ast.NotIn else

                    # Overloaded
                    '__eq__' if type (op) == ast.Eq else
                    '__ne__' if type (op) == ast.NotEq else
                    '__lt__' if type (op) == ast.Lt else
                    '__le__' if type (op) == ast.LtE else
                    '__gt__' if type (op) == ast.Gt else
                    '__ge__' if type (op) == ast.GtE else

                    'Never here'
                )))
                self.visitSubExpr (node, left)
                self.emit (', ')
                self.visitSubExpr (node, right)
                self.emit (')')
            else:
                self.visitSubExpr (node, left)
                self.emit (' {0} '.format (self.operators [type (op)][0]))
                self.visitSubExpr (node, right)

            left = right

        if len (node.comparators) > 1:
            self.emit(')') 
开发者ID:QQuick,项目名称:Transcrypt,代码行数:43,代码来源:compiler.py

示例12: _check_constant

# 需要导入模块: import ast [as 别名]
# 或者: from ast import NotEq [as 别名]
def _check_constant(self, op: ast.cmpop, comparator: ast.expr) -> None:
        if not isinstance(op, (ast.Eq, ast.NotEq, ast.Is, ast.IsNot)):
            return
        real = get_assigned_expr(comparator)
        if not isinstance(real, (ast.List, ast.Dict, ast.Tuple)):
            return

        length = len(real.keys) if isinstance(
            real, ast.Dict,
        ) else len(real.elts)

        if not length:
            self.add_violation(FalsyConstantCompareViolation(comparator)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:15,代码来源:compares.py

示例13: _check_negated_conditions

# 需要导入模块: import ast [as 别名]
# 或者: from ast import NotEq [as 别名]
def _check_negated_conditions(self, node: AnyIf) -> None:
        if isinstance(node, ast.If) and not ifs.has_else(node):
            return

        if isinstance(node.test, ast.UnaryOp):
            if isinstance(node.test.op, ast.Not):
                self.add_violation(NegatedConditionsViolation(node))
        elif isinstance(node.test, ast.Compare):
            if any(isinstance(elem, ast.NotEq) for elem in node.test.ops):
                self.add_violation(NegatedConditionsViolation(node)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:12,代码来源:conditions.py


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