From adb77e30e3ae219141380fbd9014a23cabf44af3 2013-07-17 17:28:39 From: MinRK Date: 2013-07-17 17:28:39 Subject: [PATCH] rollback UsageError for cell magic mid-cell regular SyntaxError is raised --- diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py index 9f46713..1a5f1bb 100644 --- a/IPython/core/inputtransformer.py +++ b/IPython/core/inputtransformer.py @@ -3,7 +3,6 @@ import functools import re from StringIO import StringIO -from IPython.core.error import UsageError from IPython.core.splitinput import LineInfo from IPython.utils import tokenize2 from IPython.utils.openpy import cookie_comment_re @@ -233,15 +232,6 @@ def _tr_magic(line_info): cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip() return tpl % (line_info.pre, cmd) -def _tr_cellmagic(line_info): - """Translate lines escaped with %% - - Only happens when cell magics are mid-cell, which is an error. - """ - raise UsageError("Cannot call cell magics (%s%s) mid-cell" % - (ESC_MAGIC2, line_info.ifun) - ) - def _tr_quote(line_info): "Translate lines escaped with: ," return '%s%s("%s")' % (line_info.pre, line_info.ifun, @@ -262,7 +252,6 @@ tr = { ESC_SHELL : _tr_system, ESC_HELP : _tr_help, ESC_HELP2 : _tr_help, ESC_MAGIC : _tr_magic, - ESC_MAGIC2 : _tr_cellmagic, ESC_QUOTE : _tr_quote, ESC_QUOTE2 : _tr_quote2, ESC_PAREN : _tr_paren } diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 0570cad..7bc69a7 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2599,14 +2599,10 @@ class InteractiveShell(SingletonConfigurable): if silent: store_history = False - - try: - self.input_transformer_manager.push(raw_cell) - cell = self.input_transformer_manager.source_reset() - except UsageError as e: - self.show_usage_error(e) - return - + + self.input_transformer_manager.push(raw_cell) + cell = self.input_transformer_manager.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/IPython/core/splitinput.py b/IPython/core/splitinput.py index fd8df7c..7b95772 100644 --- a/IPython/core/splitinput.py +++ b/IPython/core/splitinput.py @@ -43,7 +43,7 @@ from IPython.utils.encoding import get_stream_enc line_split = re.compile(""" ^(\s*) # any leading space - ([,;/]|%%?|!!?|\?\??)? # escape character or characters + ([,;/%]|!!?|\?\??)? # escape character or characters \s*(%{0,2}[\w\.\*]*) # function/method, possibly with leading % # to correctly treat things like '?%magic' (.*?$|$) # rest of line