MCPcopy Index your code
hub / github.com/ipython/ipython / run_ast_nodes

Method run_ast_nodes

IPython/core/interactiveshell.py:3589–3710  ·  view source on GitHub ↗

Run a sequence of AST nodes. The execution mode depends on the interactivity parameter. Parameters ---------- nodelist : list A sequence of AST nodes to run. cell_name : str Will be passed to the compiler as the filename of the cell. Typic

(
        self,
        nodelist: ListType[stmt],
        cell_name: str,
        interactivity="last_expr",
        compiler=compile,
        result=None,
    )

Source from the content-addressed store, hash-verified

3587 return node
3588
3589 async def run_ast_nodes(
3590 self,
3591 nodelist: ListType[stmt],
3592 cell_name: str,
3593 interactivity="last_expr",
3594 compiler=compile,
3595 result=None,
3596 ):
3597 """Run a sequence of AST nodes. The execution mode depends on the
3598 interactivity parameter.
3599
3600 Parameters
3601 ----------
3602 nodelist : list
3603 A sequence of AST nodes to run.
3604 cell_name : str
3605 Will be passed to the compiler as the filename of the cell. Typically
3606 the value returned by ip.compile.cache(cell).
3607 interactivity : str
3608 'all', 'last', 'last_expr' , 'last_expr_or_assign' or 'none',
3609 specifying which nodes should be run interactively (displaying output
3610 from expressions). 'last_expr' will run the last node interactively
3611 only if it is an expression (i.e. expressions in loops or other blocks
3612 are not displayed) 'last_expr_or_assign' will run the last expression
3613 or the last assignment. Other values for this parameter will raise a
3614 ValueError.
3615
3616 compiler : callable
3617 A function with the same interface as the built-in compile(), to turn
3618 the AST nodes into code objects. Default is the built-in compile().
3619 result : ExecutionResult, optional
3620 An object to store exceptions that occur during execution.
3621
3622 Returns
3623 -------
3624 True if an exception occurred while running code, False if it finished
3625 running.
3626 """
3627 if not nodelist:
3628 return
3629
3630
3631 if interactivity == 'last_expr_or_assign':
3632 if isinstance(nodelist[-1], _assign_nodes):
3633 asg = nodelist[-1]
3634 if isinstance(asg, ast.Assign) and len(asg.targets) == 1:
3635 target = asg.targets[0]
3636 elif isinstance(asg, _single_targets_nodes):
3637 target = asg.target
3638 else:
3639 target = None
3640 if isinstance(target, ast.Name):
3641 nnode = ast.Expr(ast.Name(target.id, ast.Load()))
3642 ast.fix_missing_locations(nnode)
3643 nodelist.append(nnode)
3644 interactivity = 'last_expr'
3645
3646 _async = False

Callers 1

run_cell_asyncMethod · 0.95

Calls 4

run_codeMethod · 0.95
showtracebackMethod · 0.95
softspaceFunction · 0.85
extra_flagsMethod · 0.80

Tested by

no test coverage detected