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


Python ast.AnnAssign方法代码示例

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


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

示例1: expr_stmt_rewrite

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def expr_stmt_rewrite(lhs, ann, aug, aug_exp, rhs: t.Optional[list]):
    if rhs:
        as_store(lhs)
        *init, end = rhs
        for each in init:
            as_store(each)
        return ast.Assign([lhs, *init], end)

    if ann:
        as_store(lhs)
        anno, value = ann
        return ast.AnnAssign(lhs, anno, value, 1)

    if aug_exp:
        as_store(lhs)
        return ast.AugAssign(lhs, aug(), aug_exp)

    # NO AS STORE HERE!
    return ast.Expr(lhs) 
开发者ID:Xython,项目名称:YAPyPy,代码行数:21,代码来源:helper.py

示例2: _visit_ann_assign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def _visit_ann_assign(self: 'ASTTagger', node: ast.AnnAssign):
    self.symtable.cts.add(ContextType.Annotation)
    return node 
开发者ID:Xython,项目名称:YAPyPy,代码行数:5,代码来源:symbol_analyzer.py

示例3: check_assignment

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def check_assignment(self, statement):
        msg = self.assign_msg
        if type(statement.__flake8_builtins_parent) is ast.ClassDef:
            msg = self.class_attribute_msg

        if isinstance(statement, ast.Assign):
            stack = list(statement.targets)
        else:  # This is `ast.AnnAssign` or `ast.NamedExpr`:
            stack = [statement.target]

        while stack:
            item = stack.pop()
            if isinstance(item, (ast.Tuple, ast.List)):
                stack.extend(list(item.elts))
            elif isinstance(item, ast.Name) and \
                    item.id in BUILTINS:
                yield self.error(item, message=msg, variable=item.id)
            elif PY3 and isinstance(item, ast.Starred):
                if hasattr(item.value, 'id') and item.value.id in BUILTINS:
                    yield self.error(
                        statement,
                        message=msg,
                        variable=item.value.id,
                    )
                elif hasattr(item.value, 'elts'):
                    stack.extend(list(item.value.elts)) 
开发者ID:gforcada,项目名称:flake8-builtins,代码行数:28,代码来源:flake8_builtins.py

示例4: get_var_names_from_assignment

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def get_var_names_from_assignment(
    assignment_node: Union[ast.Assign, ast.AnnAssign],
) -> List[Tuple[str, ast.AST]]:
    if isinstance(assignment_node, ast.AnnAssign):
        if isinstance(assignment_node.target, ast.Name):
            return [(assignment_node.target.id, assignment_node.target)]
    elif isinstance(assignment_node, ast.Assign):
        names = [t for t in assignment_node.targets if isinstance(t, ast.Name)]
        return [(n.id, n) for n in names]
    return [] 
开发者ID:best-doctor,项目名称:flake8-variables-names,代码行数:12,代码来源:ast_helpers.py

示例5: extract_all_variable_names

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def extract_all_variable_names(ast_tree: ast.AST) -> List[Tuple[str, ast.AST]]:
    var_info: List[Tuple[str, ast.AST]] = []
    assignments = [n for n in ast.walk(ast_tree) if isinstance(n, ast.Assign)]
    var_info += flat([get_var_names_from_assignment(a) for a in assignments])
    ann_assignments = [n for n in ast.walk(ast_tree) if isinstance(n, ast.AnnAssign)]
    var_info += flat([get_var_names_from_assignment(a) for a in ann_assignments])
    funcdefs = [n for n in ast.walk(ast_tree) if isinstance(n, ast.FunctionDef)]
    var_info += flat([get_var_names_from_funcdef(f) for f in funcdefs])
    fors = [n for n in ast.walk(ast_tree) if isinstance(n, ast.For)]
    var_info += flat([get_var_names_from_for(f) for f in fors])
    return var_info 
开发者ID:best-doctor,项目名称:flake8-variables-names,代码行数:13,代码来源:ast_helpers.py

示例6: visit_AnnAssign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def visit_AnnAssign(self, ann_assign: ast.AnnAssign) -> None:  # type: ignore
        self.visit_simple_stmt(ann_assign) 
开发者ID:NetSys,项目名称:kappa,代码行数:4,代码来源:liveness.py

示例7: get_assign_targets

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def get_assign_targets(
    node: Union[AnyAssignWithWalrus, ast.AugAssign],
) -> List[ast.expr]:
    """Returns list of assign targets without knowing the type of assign."""
    if isinstance(node, (ast.AnnAssign, ast.AugAssign, NamedExpr)):
        return [node.target]
    return node.targets 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:9,代码来源:functions.py

示例8: _maybe_ignore_child

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def _maybe_ignore_child(self, node: ast.AST) -> bool:
        if isinstance(node, ast.AnnAssign):
            self._to_ignore.extend(ast.walk(node.annotation))

        return node in self._to_ignore 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:7,代码来源:jones.py

示例9: visit_AnnAssign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
        """
        Check assignment annotation.

        Raises:
            TooComplexAnnotationViolation

        """
        self._check_annotations_complexity(node, [node.annotation])
        self.generic_visit(node) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:12,代码来源:annotations.py

示例10: _check_mutable_constant

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def _check_mutable_constant(self, node: AnyAssign) -> None:
        if not isinstance(get_context(node), ast.Module):
            return

        if isinstance(node, ast.AnnAssign):
            targets = [node.target]
        else:
            targets = node.targets

        for target in targets:
            if not isinstance(target, ast.Name) or not is_constant(target.id):
                continue

            if isinstance(node.value, self._mutable_nodes):
                self.add_violation(MutableModuleConstantViolation(target)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:17,代码来源:modules.py

示例11: is_no_value_annotation

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AnnAssign [as 别名]
def is_no_value_annotation(node: ast.AST) -> bool:
    """Check that variable has annotation without value."""
    return isinstance(node, ast.AnnAssign) and not node.value 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:5,代码来源:predicates.py


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