當前位置: 首頁>>代碼示例>>Python>>正文


Python ast.Continue方法代碼示例

本文整理匯總了Python中ast.Continue方法的典型用法代碼示例。如果您正苦於以下問題:Python ast.Continue方法的具體用法?Python ast.Continue怎麽用?Python ast.Continue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ast的用法示例。


在下文中一共展示了ast.Continue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: CONTINUE

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [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: CONTINUE

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [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

示例3: check_for_b012

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [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

示例4: _handle_ast_list

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [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

示例5: try_except_continue

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def try_except_continue(context, config):
    node = context.node
    if len(node.body) == 1:
        if (not config['check_typed_exception'] and
                node.type is not None and
                getattr(node.type, 'id', None) != 'Exception'):
            return

        if isinstance(node.body[0], ast.Continue):
            return bandit.Issue(
                severity=bandit.LOW,
                confidence=bandit.HIGH,
                text=("Try, Except, Continue detected.")) 
開發者ID:PyCQA,項目名稱:bandit,代碼行數:15,代碼來源:try_except_continue.py

示例6: _jump_absolute

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def _jump_absolute(instr, queue, stack, body, context):
    if instr.arg is context.top_of_loop:
        body.append(ast.Continue())
        return
    raise DecompilationError("Don't know how to decompile %s." % instr) 
開發者ID:llllllllll,項目名稱:codetransformer,代碼行數:7,代碼來源:_343.py

示例7: make_for_loop

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def make_for_loop(loop_body_instrs, else_body_instrs, context):
    """
    Make an ast.For node.
    """
    # Instructions from start until GET_ITER are the builders for the iterator
    # expression.
    iterator_expr = make_expr(
        popwhile(not_a(instrs.GET_ITER), loop_body_instrs, side='left')
    )

    # Next is the GET_ITER instruction, which we don't need.
    loop_body_instrs.popleft()

    # Next is FOR_ITER, which is the jump target for Continue nodes.
    top_of_loop = loop_body_instrs.popleft()

    # This can be a STORE_* or an UNPACK_SEQUENCE followed by some number of
    # stores.
    target = make_assign_target(
        loop_body_instrs.popleft(),
        loop_body_instrs,
        stack=[],
    )

    body, orelse_body = make_loop_body_and_orelse(
        top_of_loop, loop_body_instrs, else_body_instrs, context
    )

    return ast.For(
        target=target,
        iter=iterator_expr,
        body=body,
        orelse=orelse_body,
    ) 
開發者ID:llllllllll,項目名稱:codetransformer,代碼行數:36,代碼來源:_343.py

示例8: p_continue_stmt

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def p_continue_stmt(p):
    '''continue_stmt : CONTINUE'''
    #                         1
    p[0] = ast.Continue(rule=inspect.currentframe().f_code.co_name, **p[1][1])

# return_stmt: 'return' [testlist] 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:8,代碼來源:hgawk_grammar.py

示例9: gen_statement

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [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

示例10: translate_continue

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def translate_continue(self, exp):
        if len(exp) > 1:
            raise MochiSyntaxError(exp, self.filename)

        return (), ast.Continue(lineno=exp[0].lineno,
                                col_offset=0) 
開發者ID:i2y,項目名稱:mochi,代碼行數:8,代碼來源:translation.py

示例11: visit_Continue

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def visit_Continue(self, cont_stmt: ast.Continue, _ctx: CPSTransformerContext) -> VisitReturnT:
        return cont_stmt, [] 
開發者ID:NetSys,項目名稱:kappa,代碼行數:4,代碼來源:cps.py

示例12: visit_Continue

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def visit_Continue(self, cont_stmt: ast.Continue) -> ActionsT:
        # Before going into the next iteration, emit statements to re-evaluate the loop condition.
        return self.loop_cond_actions[-1] + [cont_stmt] 
開發者ID:NetSys,項目名稱:kappa,代碼行數:5,代碼來源:flatten.py

示例13: visit_Continue

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def visit_Continue(self, _cont_stmt: ast.Continue) -> None:
        pass 
開發者ID:NetSys,項目名稱:kappa,代碼行數:4,代碼來源:liveness.py

示例14: _check_break_or_continue_in_finally

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [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: _check_useless_continue

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Continue [as 別名]
def _check_useless_continue(self, node: AnyLoop) -> None:
        nodes_at_line: DefaultDict[int, List[ast.AST]] = defaultdict(list)
        for sub_node in ast.walk(node):
            lineno = getattr(sub_node, 'lineno', None)
            if lineno is not None:
                nodes_at_line[lineno].append(sub_node)

        last_line = nodes_at_line[sorted(nodes_at_line.keys())[-1]]
        if any(isinstance(last, ast.Continue) for last in last_line):
            self.add_violation(UselessContinueViolation(node)) 
開發者ID:wemake-services,項目名稱:wemake-python-styleguide,代碼行數:12,代碼來源:loops.py


注:本文中的ast.Continue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。