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

Method transform_cell

IPython/core/interactiveshell.py:3525–3553  ·  view source on GitHub ↗

Transform an input cell before parsing it. Static transformations, implemented in IPython.core.inputtransformer2, deal with things like ``%magic`` and ``!system`` commands. These run on all input. Dynamic transformations, for things like unescaped magics and the exit

(self, raw_cell)

Source from the content-addressed store, hash-verified

3523 return {"ename": etype.__name__, "evalue": str(evalue), "traceback": stb}
3524
3525 def transform_cell(self, raw_cell):
3526 """Transform an input cell before parsing it.
3527
3528 Static transformations, implemented in IPython.core.inputtransformer2,
3529 deal with things like ``%magic`` and ``!system`` commands.
3530 These run on all input.
3531 Dynamic transformations, for things like unescaped magics and the exit
3532 autocall, depend on the state of the interpreter.
3533 These only apply to single line inputs.
3534
3535 These string-based transformations are followed by AST transformations;
3536 see :meth:`transform_ast`.
3537 """
3538 # Static input transformations
3539 cell = self.input_transformer_manager.transform_cell(raw_cell)
3540
3541 if len(cell.splitlines()) == 1:
3542 # Dynamic transformations - only applied for single line commands
3543 with self.builtin_trap:
3544 # use prefilter_lines to handle trailing newlines
3545 # restore trailing newline for ast.parse
3546 cell = self.prefilter_manager.prefilter_lines(cell) + '\n'
3547
3548 lines = cell.splitlines(keepends=True)
3549 for transform in self.input_transformers_post:
3550 lines = transform(lines)
3551 cell = ''.join(lines)
3552
3553 return cell
3554
3555 def transform_ast(self, node):
3556 """Apply the AST transformations from self.ast_transformers

Callers 7

_run_cellMethod · 0.95
should_run_asyncMethod · 0.95
run_cell_asyncMethod · 0.95
prunMethod · 0.45
timeMethod · 0.45
ip2pyMethod · 0.45
run_codeMethod · 0.45

Calls 1

prefilter_linesMethod · 0.80

Tested by 2

ip2pyMethod · 0.36
run_codeMethod · 0.36