MCPcopy Create free account
hub / github.com/ipython/ipython / push

Method push

IPython/core/inputsplitter.py:680–727  ·  view source on GitHub ↗

Push one or more lines of IPython input. This stores the given lines and returns a status code indicating whether the code forms a complete Python block or not, after processing all input lines for special IPython syntax. Any exceptions generated in compilation are

(self, lines:str)

Source from the content-addressed store, hash-verified

678 self.reset()
679
680 def push(self, lines:str) -> bool:
681 """Push one or more lines of IPython input.
682
683 This stores the given lines and returns a status code indicating
684 whether the code forms a complete Python block or not, after processing
685 all input lines for special IPython syntax.
686
687 Any exceptions generated in compilation are swallowed, but if an
688 exception was produced, the method returns True.
689
690 Parameters
691 ----------
692 lines : string
693 One or more lines of Python input.
694
695 Returns
696 -------
697 is_complete : boolean
698 True if the current input source (the result of the current input
699 plus prior inputs) forms a complete Python execution block. Note that
700 this value is also stored as a private attribute (_is_complete), so it
701 can be queried at any time.
702 """
703 assert isinstance(lines, str)
704 # We must ensure all input is pure unicode
705 # ''.splitlines() --> [], but we need to push the empty line to transformers
706 lines_list = lines.splitlines()
707 if not lines_list:
708 lines_list = ['']
709
710 # Store raw source before applying any transformations to it. Note
711 # that this must be done *after* the reset() call that would otherwise
712 # flush the buffer.
713 self._store(lines, self._buffer_raw, 'source_raw')
714
715 transformed_lines_list = []
716 for line in lines_list:
717 transformed = self._transform_line(line)
718 if transformed is not None:
719 transformed_lines_list.append(transformed)
720
721 if transformed_lines_list:
722 transformed_lines = '\n'.join(transformed_lines_list)
723 return super(IPythonInputSplitter, self).push(transformed_lines)
724 else:
725 # Got nothing back from transformers - they must be waiting for
726 # more input.
727 return False
728
729 def _transform_line(self, line):
730 """Push a line of input code through the various transformers.

Callers 1

transform_cellMethod · 0.95

Calls 3

_transform_lineMethod · 0.95
_storeMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected