diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 2795b52..d4988e7 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2172,7 +2172,9 @@ class InteractiveShell(SingletonConfigurable, Magic): prefilter_failed = False if len(cell.splitlines()) == 1: try: - cell = self.prefilter_manager.prefilter_line(cell) + # use prefilter_lines to handle trailing newlines + # restore trailing newline for ast.parse + cell = self.prefilter_manager.prefilter_lines(cell) + '\n' except AliasError as e: error(e) prefilter_failed=True diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 904e6f8..b4e5fcf 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -106,4 +106,11 @@ class InteractiveShellTestCase(unittest.TestCase): err = io.stderr.getvalue() io.stderr = save_err self.assertEquals(err.split(':')[0], 'ERROR') + + def test_trailing_newline(self): + """test that running !(command) does not raise a SyntaxError""" + ip = get_ipython() + ip.run_cell('!(true)\n', False) + ip.run_cell('!(true)\n\n\n', False) +