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


Python ast.cmpop方法代码示例

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


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

示例1: _compare_to_3

# 需要导入模块: import ast [as 别名]
# 或者: from ast import cmpop [as 别名]
def _compare_to_3(
        test: ast.Compare,
        op: Union[Type[ast.cmpop], Tuple[Type[ast.cmpop], ...]],
    ) -> bool:
        if not (
                isinstance(test.ops[0], op) and
                isinstance(test.comparators[0], ast.Tuple) and
                len(test.comparators[0].elts) >= 1 and
                all(isinstance(n, ast.Num) for n in test.comparators[0].elts)
        ):
            return False

        # checked above but mypy needs help
        elts = cast('List[ast.Num]', test.comparators[0].elts)

        return elts[0].n == 3 and all(n.n == 0 for n in elts[1:]) 
开发者ID:asottile,项目名称:pyupgrade,代码行数:18,代码来源:pyupgrade.py

示例2: _is_correct_len

# 需要导入模块: import ast [as 别名]
# 或者: from ast import cmpop [as 别名]
def _is_correct_len(sign: ast.cmpop, comparator: ast.AST) -> bool:
    """This is a helper function to tell what calls to ``len()`` are valid."""
    if isinstance(operators.unwrap_unary_node(comparator), ast.Num):
        numeric_value = ast.literal_eval(comparator)
        if numeric_value == 0:
            return False
        if numeric_value == 1:
            return not isinstance(sign, (ast.GtE, ast.Lt))
    return True 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:11,代码来源:compares.py

示例3: _check_constant

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

示例4: _check_is_constant_comprare

# 需要导入模块: import ast [as 别名]
# 或者: from ast import cmpop [as 别名]
def _check_is_constant_comprare(
        self,
        op: ast.cmpop,
        comparator: ast.expr,
    ) -> None:
        if not isinstance(op, (ast.Is, ast.IsNot)):
            return

        unwrapped = operators.unwrap_unary_node(
            get_assigned_expr(comparator),
        )
        if isinstance(unwrapped, self._forbidden_for_is):
            self.add_violation(WrongIsCompareViolation(comparator)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:15,代码来源:compares.py

示例5: get_similar_operators

# 需要导入模块: import ast [as 别名]
# 或者: from ast import cmpop [as 别名]
def get_similar_operators(
    operator: ast.cmpop,
) -> Union[Type[ast.cmpop], _MultipleCompareOperators]:
    """Returns similar operators types for the given operator."""
    operator_type = operator.__class__
    return SIMILAR_OPERATORS.get(operator_type, operator_type) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:8,代码来源:compares.py

示例6: _mutate

# 需要导入模块: import ast [as 别名]
# 或者: from ast import cmpop [as 别名]
def _mutate(
        self,
        comparison_node: ast.Compare,
        operator: ast.cmpop,
        name: str,
        is_left: bool,
    ) -> None:
        key_name = None
        if isinstance(operator, (ast.Lt, ast.LtE)):
            key_name = 'lower_bound' if is_left else 'upper_bound'
        elif isinstance(operator, (ast.Gt, ast.GtE)):
            key_name = 'upper_bound' if is_left else 'lower_bound'

        if key_name:
            getattr(self._uses[name], key_name).add(comparison_node) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:17,代码来源:compares.py


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