From 520fed4785a2b7bfefe1843a92b49ce23b44ab1c 2012-05-27 02:44:01 From: Fernando Perez Date: 2012-05-27 02:44:01 Subject: [PATCH] Fix handling of lines like '%%foo?' in cell magic logic. --- diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index d4de3f6..e78ed2e 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -60,7 +60,6 @@ Authors # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. #----------------------------------------------------------------------------- -from __future__ import print_function #----------------------------------------------------------------------------- # Imports @@ -598,7 +597,6 @@ def _make_help_call(target, esc, lspace, next_input=None): else 'psearch' if '*' in target \ else 'pinfo' arg = " ".join([method, target]) - if next_input is None: return '%sget_ipython().magic(%r)' % (lspace, arg) else: @@ -608,7 +606,7 @@ def _make_help_call(target, esc, lspace, next_input=None): _initial_space_re = re.compile(r'\s*') -_help_end_re = re.compile(r"""(%? +_help_end_re = re.compile(r"""(%{0,2} [a-zA-Z_*][\w*]* # Variable name (\.[a-zA-Z_*][\w*]*)* # .etc.etc ) @@ -841,7 +839,8 @@ class IPythonInputSplitter(InputSplitter): # If the entire input block is a cell magic, return after handling it # as the rest of the transformation logic should be skipped. - if lines.startswith('%%'): + if lines.startswith('%%') and not \ + (len(lines.splitlines()) == 1 and lines.endswith('?')): return self._handle_cell_magic(lines) # In line mode, a cell magic can arrive in separate pieces diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index 1ddf97a..f5b6599 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -455,7 +455,8 @@ syntax = \ (u'?x1', "get_ipython().magic({u}'pinfo x1')"), (u'??x2', "get_ipython().magic({u}'pinfo2 x2')"), (u'?a.*s', "get_ipython().magic({u}'psearch a.*s')"), - (u'?%hist', "get_ipython().magic({u}'pinfo %hist')"), + (u'?%hist1', "get_ipython().magic({u}'pinfo %hist1')"), + (u'?%%hist2', "get_ipython().magic({u}'pinfo %%hist2')"), (u'?abc = qwe', "get_ipython().magic({u}'pinfo abc')"), ]], @@ -463,7 +464,10 @@ syntax = \ [(i,py3compat.u_format(o)) for i,o in \ [ (u'x3?', "get_ipython().magic({u}'pinfo x3')"), (u'x4??', "get_ipython().magic({u}'pinfo2 x4')"), - (u'%hist?', "get_ipython().magic({u}'pinfo %hist')"), + (u'%hist1?', "get_ipython().magic({u}'pinfo %hist1')"), + (u'%hist2??', "get_ipython().magic({u}'pinfo2 %hist2')"), + (u'%%hist3?', "get_ipython().magic({u}'pinfo %%hist3')"), + (u'%%hist4??', "get_ipython().magic({u}'pinfo2 %%hist4')"), (u'f*?', "get_ipython().magic({u}'psearch f*')"), (u'ax.*aspe*?', "get_ipython().magic({u}'psearch ax.*aspe*')"), (u'a = abc?', "get_ipython().set_next_input({u}'a = abc');"