diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index f308f8c..b85e73a 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2106,24 +2106,28 @@ class InteractiveShell(Configurable, Magic): self.showtraceback() warn('Unknown failure executing file: <%s>' % fname) - def run_cell(self, cell, store_history=True): + def run_cell(self, raw_cell, store_history=True): """Run a complete IPython cell. Parameters ---------- - cell : str + raw_cell : str The code (including IPython code such as %magic functions) to run. store_history : bool If True, the raw and translated cell will be stored in IPython's history. For user code calling back into IPython's machinery, this should be set to False. """ - if not cell.strip(): + if not raw_cell.strip(): return - raw_cell = cell + for line in raw_cell.splitlines(): + self.input_splitter.push(line) + cell = self.input_splitter.source_reset() + with self.builtin_trap: - cell = self.prefilter_manager.prefilter_lines(cell) + if len(cell.splitlines()) == 1: + cell = self.prefilter_manager.prefilter_lines(cell) # Store raw and processed history if store_history: diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 560f2a4..3e930b7 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -89,5 +89,5 @@ class InteractiveShellTestCase(unittest.TestCase): def test_magic_names_in_string(self): ip = get_ipython() - ip.run_cell('"""\n%exit\n"""') - self.assertEquals(ip.user_ns['In'][-1], '\n%exit\n') + ip.run_cell('a = """\n%exit\n"""') + self.assertEquals(ip.user_ns['a'], '\n%exit\n')