Python ast.Continue() Examples
The following are 17
code examples of ast.Continue().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ast
, or try the search function
.
Example #1
Source File: checker.py From pyflakes with MIT License | 6 votes |
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)
Example #2
Source File: checker.py From blackmamba with MIT License | 6 votes |
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)
Example #3
Source File: bugbear.py From flake8-bugbear with MIT License | 6 votes |
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))
Example #4
Source File: checker.py From linter-pylama with MIT License | 6 votes |
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)
Example #5
Source File: core.py From vulture with MIT License | 6 votes |
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
Example #6
Source File: python2ir.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
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)
Example #7
Source File: loops.py From wemake-python-styleguide with MIT License | 5 votes |
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))
Example #8
Source File: exceptions.py From wemake-python-styleguide with MIT License | 5 votes |
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))
Example #9
Source File: liveness.py From kappa with BSD 2-Clause "Simplified" License | 5 votes |
def visit_Continue(self, _cont_stmt: ast.Continue) -> None: pass
Example #10
Source File: flatten.py From kappa with BSD 2-Clause "Simplified" License | 5 votes |
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]
Example #11
Source File: cps.py From kappa with BSD 2-Clause "Simplified" License | 5 votes |
def visit_Continue(self, cont_stmt: ast.Continue, _ctx: CPSTransformerContext) -> VisitReturnT: return cont_stmt, []
Example #12
Source File: translation.py From mochi with MIT License | 5 votes |
def translate_continue(self, exp): if len(exp) > 1: raise MochiSyntaxError(exp, self.filename) return (), ast.Continue(lineno=exp[0].lineno, col_offset=0)
Example #13
Source File: hgawk_grammar.py From histogrammar-python with Apache License 2.0 | 5 votes |
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]
Example #14
Source File: _343.py From codetransformer with GNU General Public License v2.0 | 5 votes |
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, )
Example #15
Source File: _343.py From codetransformer with GNU General Public License v2.0 | 5 votes |
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)
Example #16
Source File: try_except_continue.py From bandit with Apache License 2.0 | 5 votes |
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."))
Example #17
Source File: translation.py From mochi with MIT License | 4 votes |
def visit_Return(self, node): if isinstance(node.value, ast.Call) and isinstance(node.value.func, ast.Name): if node.value.func.id == self.target_func.name: self.__class__.optimized = True tmp_result = [] result = [] default_values = [] + self.target_func.args.defaults for arg in self.target_func.args.args: arg_name = ast.Name(id=arg.arg, ctx=ast.Store(), lineno=0, col_offset=0) try: arg_value = node.value.args.pop(0) except IndexError: arg_value = default_values.pop(0) tmp_arg_sym = get_temp_name() tmp_arg_name = ast.Name(id=tmp_arg_sym.name, ctx=ast.Store(), lineno=0, col_offset=0) arg_value_assign = ast.Assign(targets=[tmp_arg_name], value=arg_value, lineno=0, col_offset=0) tmp_result.append(arg_value_assign) arg_value_ref = translator.translate_ref(tmp_arg_sym)[1] arg_re_assign = ast.Assign(targets=[arg_name], value=arg_value_ref, lineno=0, col_offset=0) arg_re_assign.re_assign = True result.append(arg_re_assign) if self.target_func.args.vararg is not None: vararg = self.target_func.args.vararg arg_name = ast.Name(id=vararg.arg if GE_PYTHON_34 else vararg, ctx=ast.Store(), lineno=0, col_offset=0) arg_value = ast.Tuple(elts=node.value.args, lineno=0, col_offset=0, ctx=ast.Load()) arg_re_assign = ast.Assign(targets=[arg_name], value=arg_value, lineno=0, col_offset=0) arg_re_assign.re_assign = True result.append(arg_re_assign) result.append(ast.Continue(lineno=0, col_offset=0)) return tmp_result + result return node