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


Python ast.Break方法代码示例

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


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

示例1: CONTINUE

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def CONTINUE(self, node):
        # Walk the tree up until we see a loop (OK), a function or class
        # definition (not OK), for 'continue', a finally block (not OK), or
        # the top module scope (not OK)
        n = node
        while hasattr(n, 'parent'):
            n, n_child = n.parent, n
            if isinstance(n, LOOP_TYPES):
                # Doesn't apply unless it's in the loop itself
                if n_child not in n.orelse:
                    return
            if isinstance(n, (ast.FunctionDef, ast.ClassDef)):
                break
            # Handle Try/TryFinally difference in Python < and >= 3.3
            if hasattr(n, 'finalbody') and isinstance(node, ast.Continue):
                if n_child in n.finalbody:
                    self.report(messages.ContinueInFinally, node)
                    return
        if isinstance(node, ast.Continue):
            self.report(messages.ContinueOutsideLoop, node)
        else:  # ast.Break
            self.report(messages.BreakOutsideLoop, node) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:24,代码来源:checker.py

示例2: __exit_scope

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def __exit_scope(self) -> ast.stmt:
        """Create the appropriate scope exiting statement.

        The documentation only shows one level and always uses
        'return False' in examples.

        'raise AltFalse()' within a try.
        'break' within a loop.
        'return False' otherwise.
        """
        if self.in_optional:
            return ast.Pass()
        if self.in_try:
            return ast.Raise(
                ast.Call(ast.Name('AltFalse', ast.Load()), [], [], None, None),
                None)
        if self.in_loop:
            return ast.Break()
        return ast.Return(ast.Name('False', ast.Load()))

    #TODO(bps): find a better name to describe what this does 
开发者ID:LionelAuroux,项目名称:pyrser,代码行数:23,代码来源:topython.py

示例3: CONTINUE

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def CONTINUE(self, node):
        # Walk the tree up until we see a loop (OK), a function or class
        # definition (not OK), for 'continue', a finally block (not OK), or
        # the top module scope (not OK)
        n = node
        while hasattr(n, '_pyflakes_parent'):
            n, n_child = n._pyflakes_parent, n
            if isinstance(n, LOOP_TYPES):
                # Doesn't apply unless it's in the loop itself
                if n_child not in n.orelse:
                    return
            if isinstance(n, (ast.FunctionDef, ast.ClassDef)):
                break
            # Handle Try/TryFinally difference in Python < and >= 3.3
            if hasattr(n, 'finalbody') and isinstance(node, ast.Continue):
                if n_child in n.finalbody and not PY38_PLUS:
                    self.report(messages.ContinueInFinally, node)
                    return
        if isinstance(node, ast.Continue):
            self.report(messages.ContinueOutsideLoop, node)
        else:  # ast.Break
            self.report(messages.BreakOutsideLoop, node) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:24,代码来源:checker.py

示例4: check_for_b012

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def check_for_b012(self, node):
        def _loop(node, bad_node_types):
            if isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef)):
                return

            if isinstance(node, (ast.While, ast.For)):
                bad_node_types = (ast.Return,)

            elif isinstance(node, bad_node_types):
                self.errors.append(B012(node.lineno, node.col_offset))

            for child in ast.iter_child_nodes(node):
                _loop(child, bad_node_types)

        for child in node.finalbody:
            _loop(child, (ast.Return, ast.Continue, ast.Break)) 
开发者ID:PyCQA,项目名称:flake8-bugbear,代码行数:18,代码来源:bugbear.py

示例5: _handle_ast_list

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def _handle_ast_list(self, ast_list):
        """
        Find unreachable nodes in the given sequence of ast nodes.
        """
        for index, node in enumerate(ast_list):
            if isinstance(
                node, (ast.Break, ast.Continue, ast.Raise, ast.Return)
            ):
                try:
                    first_unreachable_node = ast_list[index + 1]
                except IndexError:
                    continue
                class_name = node.__class__.__name__.lower()
                self._define(
                    self.unreachable_code,
                    class_name,
                    first_unreachable_node,
                    last_node=ast_list[-1],
                    message="unreachable code after '{class_name}'".format(
                        **locals()
                    ),
                    confidence=100,
                )
                return 
开发者ID:jendrikseipp,项目名称:vulture,代码行数:26,代码来源:core.py

示例6: _jump_break_loop

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def _jump_break_loop(instr, queue, stack, body, context):
    if context.top_of_loop is None:
        raise DecompilationError("BREAK_LOOP outside of loop.")
    body.append(ast.Break()) 
开发者ID:llllllllll,项目名称:codetransformer,代码行数:6,代码来源:_343.py

示例7: p_break_stmt

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def p_break_stmt(p):
    '''break_stmt : BREAK'''
    #                   1
    p[0] = ast.Break(rule=inspect.currentframe().f_code.co_name, **p[1][1])

# continue_stmt: 'continue' 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:8,代码来源:hgawk_grammar.py

示例8: gen_statement

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def gen_statement(self, statement):
        """ Generate code for a statement """
        if isinstance(statement, list):
            for inner_statement in statement:
                self.gen_statement(inner_statement)
        else:
            with self.use_location(statement):
                if isinstance(statement, ast.Pass):
                    pass  # No comments :)
                elif isinstance(statement, ast.Return):
                    self.gen_return(statement)
                elif isinstance(statement, ast.If):
                    self.gen_if(statement)
                elif isinstance(statement, ast.While):
                    self.gen_while(statement)
                elif isinstance(statement, ast.Break):
                    self.gen_break(statement)
                elif isinstance(statement, ast.Continue):
                    self.gen_continue(statement)
                elif isinstance(statement, ast.For):
                    self.gen_for(statement)
                elif isinstance(statement, ast.Assign):
                    self.gen_assign(statement)
                elif isinstance(statement, ast.Expr):
                    self.gen_expr(statement.value)
                elif isinstance(statement, ast.AugAssign):
                    self.gen_aug_assign(statement)
                else:  # pragma: no cover
                    self.not_impl(statement) 
开发者ID:windelbouwman,项目名称:ppci,代码行数:31,代码来源:python2ir.py

示例9: translate_break

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def translate_break(self, exp):
        if len(exp) > 1:
            raise MochiSyntaxError(exp, self.filename)

        return (), ast.Break(lineno=exp[0].lineno,
                             col_offset=0) 
开发者ID:i2y,项目名称:mochi,代码行数:8,代码来源:translation.py

示例10: _tail_recursion_optimize

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def _tail_recursion_optimize(self, func_ast):
        transformer = self.SelfTailRecursiveCallTransformer(func_ast)
        optimized_func_ast = transformer.visit(func_ast)

        if self.SelfTailRecursiveCallTransformer.optimized:
            if IS_PYPY:
                optimized_func_ast.body = [ast.While(test=ast.Name(id='True',
                                                                   ctx=ast.Load(),
                                                                   lineno=0,
                                                                   col_offset=0),
                                                     body=optimized_func_ast.body + [ast.Break(lineno=0,
                                                                                               col_offset=0)],
                                                     orelse=[],
                                                     lineno=0,
                                                     col_offset=0)]
            else:
                optimized_func_ast.body = [ast.While(test=ast.Num(n=1,
                                                                  lineno=0,
                                                                  col_offset=0),
                                                     body=optimized_func_ast.body + [ast.Break(lineno=0,
                                                                                               col_offset=0)],
                                                     orelse=[],
                                                     lineno=0,
                                                     col_offset=0)]
            self.SelfTailRecursiveCallTransformer.optimized = False
            return optimized_func_ast
        else:
            return func_ast 
开发者ID:i2y,项目名称:mochi,代码行数:30,代码来源:translation.py

示例11: visit_Break

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def visit_Break(self, br: ast.Break, _ctx: CPSTransformerContext) -> VisitReturnT:
        return br, [] 
开发者ID:NetSys,项目名称:kappa,代码行数:4,代码来源:cps.py

示例12: visit_Break

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def visit_Break(self, br: ast.Break) -> ActionsT:
        return [br] 
开发者ID:NetSys,项目名称:kappa,代码行数:4,代码来源:flatten.py

示例13: visit_Break

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

示例14: _check_break_or_continue_in_finally

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def _check_break_or_continue_in_finally(self, node: ast.Try) -> None:
        has_wrong_nodes = any(
            is_contained(line, (ast.Break, ast.Continue))
            for line in node.finalbody
        )

        if has_wrong_nodes:
            self.add_violation(LoopControlFinallyViolation(node)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:10,代码来源:exceptions.py

示例15: has_break

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Break [as 别名]
def has_break(node: AnyLoop) -> bool:
    """Tells whether or not given loop has ``break`` keyword in its body."""
    closest_loop = None

    for sub in ast.walk(node):
        if _is_nested_loop(node, sub):
            closest_loop = sub

        if isinstance(sub, ast.Break):
            if not closest_loop or not walk.is_contained_by(sub, closest_loop):
                return True
    return False 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:14,代码来源:loops.py


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