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