From 014d7ca7c6cbad46261c9df86aa5e04cdddf917b 2013-04-20 10:33:34 From: Thomas Kluyver Date: 2013-04-20 10:33:34 Subject: [PATCH] Separate InteractiveShell.input_splitter into two instances. * input_splitter is used to detect when a cell is complete * input_transformer_manager transforms completed cells Closes gh-3178 --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 69471bc..768b3e0 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -283,10 +283,16 @@ class InteractiveShell(SingletonConfigurable): filename = Unicode("") ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__ - # Input splitter, to split entire cells of input into either individual - # interactive statements or whole blocks. + # Input splitter, to transform input line by line and detect when a block + # is ready to be executed. input_splitter = Instance('IPython.core.inputsplitter.IPythonInputSplitter', - (), {}) + (), {'line_input_checker': True}) + + # This InputSplitter instance is used to transform completed cells before + # running them. It allows cell magics to contain blank lines. + input_transformer_manager = Instance('IPython.core.inputsplitter.IPythonInputSplitter', + (), {'line_input_checker': False}) + logstart = CBool(False, config=True, help= """ Start logging to the default log file. @@ -2581,10 +2587,9 @@ class InteractiveShell(SingletonConfigurable): if silent: store_history = False - self.input_splitter.push(raw_cell) + self.input_transformer_manager.push(raw_cell) + cell = self.input_transformer_manager.source_reset() - cell = self.input_splitter.source_reset() - # Our own compiler remembers the __future__ environment. If we want to # run code with a separate __future__ environment, use the default # compiler diff --git a/docs/source/config/inputtransforms.txt b/docs/source/config/inputtransforms.txt index 716d726..a28c13d 100644 --- a/docs/source/config/inputtransforms.txt +++ b/docs/source/config/inputtransforms.txt @@ -35,6 +35,14 @@ in attributes of :class:`~IPython.core.inputsplitter.IPythonInputSplitter`: passed to these, but note that function and class *definitions* are still a series of separate statements. IPython does not use any of these by default. +An InteractiveShell instance actually has two +:class:`~IPython.core.inputsplitter.IPythonInputSplitter` instances, as the +attributes :attr:`~IPython.core.interactiveshell.InteractiveShell.input_splitter`, +to tell when a block of input is complete, and +:attr:`~IPython.core.interactiveshell.InteractiveShell.input_transformer_manager`, +to transform complete cells. If you add a transformer, you should make sure that +it gets added to both. + Stateless transformations -------------------------