diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 53ec1a9..e2e7ebe 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2092,19 +2092,20 @@ class InteractiveShell(Configurable, Magic): # Store the untransformed code raw_cell = cell - # We only do dynamic transforms on a single line. We need to do this - # first, because a macro can be expanded to several lines, which then - # need to be split into blocks again. - if len(cell.splitlines()) <= 1: - temp = self.input_splitter.split_blocks(cell) - cell = self.prefilter_manager.prefilter_line(temp[0]) - # We need to break up the input into executable blocks that can be run # in 'single' mode, to provide comfortable user behavior. blocks = self.input_splitter.split_blocks(cell) - if not blocks: + if not blocks: # Blank cell return + + # We only do dynamic transforms on a single line. But a macro can + # be expanded to several lines, so we need to split it into input + # blocks again. + if len(cell.splitlines()) <= 1: + cell = self.prefilter_manager.prefilter_line(blocks[0]) + blocks = self.input_splitter.split_blocks(cell) + # Store the 'ipython' version of the cell as well, since that's what # needs to go into the translated history and get executed (the diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 3a081cf..c0f96e5 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -35,3 +35,9 @@ class InteractiveShellTestCase(unittest.TestCase): # And also multi-line cells ip.run_cell('"""a\nb"""\n') self.assertEquals(ip.user_ns['_'], 'a\nb') + + def test_run_empty_cell(self): + """Just make sure we don't get a horrible error with a blank + cell of input. Yes, I did overlook that.""" + ip = get_ipython() + ip.run_cell('')