MCPcopy Index your code
hub / github.com/python/mypy / loop_contents

Function loop_contents

mypyc/irbuild/for_helpers.py:431–459  ·  view source on GitHub ↗

Generate the body of the loop. Args: conds: a list of conditions to be evaluated (in order, with short circuiting) to gate the body of the loop remaining_loop_params: the parameters for any further nested loops; if it's empty we'll ins

(
        conds: list[Expression],
        remaining_loop_params: list[tuple[Lvalue, Expression, list[Expression], bool]],
    )

Source from the content-addressed store, hash-verified

429 )
430
431 def loop_contents(
432 conds: list[Expression],
433 remaining_loop_params: list[tuple[Lvalue, Expression, list[Expression], bool]],
434 ) -> None:
435 """Generate the body of the loop.
436
437 Args:
438 conds: a list of conditions to be evaluated (in order, with short circuiting)
439 to gate the body of the loop
440 remaining_loop_params: the parameters for any further nested loops; if it's empty
441 we'll instead evaluate the "gen_inner_stmts" function
442 """
443 # Check conditions, in order, short circuiting them.
444 for cond in conds:
445 cond_val = builder.accept(cond)
446 cont_block, rest_block = BasicBlock(), BasicBlock()
447 # If the condition is true we'll skip the continue.
448 builder.add_bool_branch(cond_val, rest_block, cont_block)
449 builder.activate_block(cont_block)
450 builder.nonlocal_control[-1].gen_continue(builder, cond.line)
451 builder.goto_and_activate(rest_block)
452
453 if remaining_loop_params:
454 # There's another nested level, so the body of this loop is another loop.
455 return handle_loop(remaining_loop_params)
456 else:
457 # We finally reached the actual body of the generator.
458 # Generate the IR for the inner loop body.
459 gen_inner_stmts()
460
461 handle_loop(loop_params)
462

Callers 1

handle_loopFunction · 0.85

Calls 8

BasicBlockClass · 0.90
handle_loopFunction · 0.85
gen_inner_stmtsFunction · 0.70
acceptMethod · 0.45
add_bool_branchMethod · 0.45
activate_blockMethod · 0.45
gen_continueMethod · 0.45
goto_and_activateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…