From 441946f1b47462cb0827098e95a3d3d642941b11 2011-07-13 22:49:24 From: Thomas Kluyver Date: 2011-07-13 22:49:24 Subject: [PATCH] Only tell the user about %paste in the terminal shell. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 395153c..1f552a7 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1605,6 +1605,10 @@ class InteractiveShell(SingletonConfigurable, Magic): value = msg, (filename, lineno, offset, line) stb = self.SyntaxTB.structured_traceback(etype, value, []) self._showtraceback(etype, value, stb) + + # This is overridden in TerminalInteractiveShell to show a message about + # the %paste magic. + showindentationerror = showsyntaxerror #------------------------------------------------------------------------- # Things related to readline @@ -2274,8 +2278,7 @@ class InteractiveShell(SingletonConfigurable, Magic): try: code_ast = ast.parse(cell, filename=cell_name) except IndentationError: - self.showsyntaxerror() - print("If you want to paste code into IPython, try the %paste magic function.") + self.showindentationerror() self.execution_count += 1 return None except (OverflowError, SyntaxError, ValueError, TypeError, diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index 2e1d183..e78f89e 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -588,6 +588,10 @@ class TerminalInteractiveShell(InteractiveShell): write("## -- End pasted text --\n") self._execute_block(block, par) + + def showindentationerror(self): + super(TerminalInteractiveShell, self).showindentationerror() + print("If you want to paste code into IPython, try the %paste magic function.") InteractiveShellABC.register(TerminalInteractiveShell)