diff --git a/IPython/core/tests/test_inputtransformer.py b/IPython/core/tests/test_inputtransformer.py index 0d97fd4..bf0d1af 100644 --- a/IPython/core/tests/test_inputtransformer.py +++ b/IPython/core/tests/test_inputtransformer.py @@ -3,7 +3,6 @@ import nose.tools as nt from IPython.testing import tools as tt from IPython.utils import py3compat -u_fmt = py3compat.u_format from IPython.core import inputtransformer as ipt @@ -38,7 +37,6 @@ def transform_checker(tests, transformer, **kwargs): syntax = \ dict(assign_system = - [(i,py3compat.u_format(o)) for i,o in \ [(u'a =! ls', "a = get_ipython().getoutput('ls')"), (u'b = !ls', "b = get_ipython().getoutput('ls')"), (u'c= !ls', "c = get_ipython().getoutput('ls')"), @@ -53,10 +51,9 @@ syntax = \ (u"a, b = range(2)", u"a, b = range(2)"), (u"a, = range(1)", u"a, = range(1)"), (u"a, *bc = range(3)", u"a, *bc = range(3)"), - ]], + ], assign_magic = - [(i,py3compat.u_format(o)) for i,o in \ [(u'a =% who', "a = get_ipython().run_line_magic('who', '')"), (u'b = %who', "b = get_ipython().run_line_magic('who', '')"), (u'c= %ls', "c = get_ipython().run_line_magic('ls', '')"), @@ -64,7 +61,7 @@ syntax = \ ('x=1', 'x=1'), # normal input is unmodified (' ',' '), # blank lines are kept intact (u"a, b = %foo", u"a, b = get_ipython().run_line_magic('foo', '')"), - ]], + ], classic_prompt = [('>>> x=1', 'x=1'), @@ -86,16 +83,14 @@ syntax = \ # System calls escaped_shell = - [(i,py3compat.u_format(o)) for i,o in \ [ (u'!ls', "get_ipython().system('ls')"), # Double-escape shell, this means to capture the output of the # subprocess and return it (u'!!ls', "get_ipython().getoutput('ls')"), - ]], + ], # Help/object info escaped_help = - [(i,py3compat.u_format(o)) for i,o in \ [ (u'?', 'get_ipython().show_usage()'), (u'?x1', "get_ipython().run_line_magic('pinfo', 'x1')"), (u'??x2', "get_ipython().run_line_magic('pinfo2', 'x2')"), @@ -103,10 +98,9 @@ syntax = \ (u'?%hist1', "get_ipython().run_line_magic('pinfo', '%hist1')"), (u'?%%hist2', "get_ipython().run_line_magic('pinfo', '%%hist2')"), (u'?abc = qwe', "get_ipython().run_line_magic('pinfo', 'abc')"), - ]], + ], end_help = - [(i,py3compat.u_format(o)) for i,o in \ [ (u'x3?', "get_ipython().run_line_magic('pinfo', 'x3')"), (u'x4??', "get_ipython().run_line_magic('pinfo2', 'x4')"), (u'%hist1?', "get_ipython().run_line_magic('pinfo', '%hist1')"), @@ -125,17 +119,16 @@ syntax = \ (u'plot(a?', "get_ipython().set_next_input('plot(a');" "get_ipython().run_line_magic('pinfo', 'a')"), (u'a*2 #comment?', 'a*2 #comment?'), - ]], + ], # Explicit magic calls escaped_magic = - [(i,py3compat.u_format(o)) for i,o in \ [ (u'%cd', "get_ipython().run_line_magic('cd', '')"), (u'%cd /home', "get_ipython().run_line_magic('cd', '/home')"), # Backslashes need to be escaped. (u'%cd C:\\User', "get_ipython().run_line_magic('cd', 'C:\\\\User')"), (u' %magic', " get_ipython().run_line_magic('magic', '')"), - ]], + ], # Quoting with separate arguments escaped_quote = @@ -163,13 +156,12 @@ syntax = \ # Check that we transform prompts before other transforms mixed = - [(i,py3compat.u_format(o)) for i,o in \ [ (u'In [1]: %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"), (u'>>> %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"), (u'In [2]: !ls', "get_ipython().system('ls')"), (u'In [3]: abs?', "get_ipython().run_line_magic('pinfo', 'abs')"), (u'In [4]: b = %who', "b = get_ipython().run_line_magic('who', '')"), - ]], + ], ) # multiline syntax examples. Each of these should be a list of lists, with @@ -284,11 +276,11 @@ syntax_ml = \ cellmagic = [ [(u'%%foo a', None), - (None, u_fmt("get_ipython().run_cell_magic('foo', 'a', '')")), + (None, "get_ipython().run_cell_magic('foo', 'a', '')"), ], [(u'%%bar 123', None), (u'hello', None), - (None , u_fmt("get_ipython().run_cell_magic('bar', '123', 'hello')")), + (None , "get_ipython().run_cell_magic('bar', '123', 'hello')"), ], [(u'a=5', 'a=5'), (u'%%cellmagic', '%%cellmagic'), @@ -297,31 +289,31 @@ syntax_ml = \ escaped = [ [('%abc def \\', None), - ('ghi', u_fmt("get_ipython().run_line_magic('abc', 'def ghi')")), + ('ghi', "get_ipython().run_line_magic('abc', 'def ghi')"), ], [('%abc def \\', None), ('ghi\\', None), - (None, u_fmt("get_ipython().run_line_magic('abc', 'def ghi')")), + (None, "get_ipython().run_line_magic('abc', 'def ghi')"), ], ], assign_magic = [ [(u'a = %bc de \\', None), - (u'fg', u_fmt("a = get_ipython().run_line_magic('bc', 'de fg')")), + (u'fg', "a = get_ipython().run_line_magic('bc', 'de fg')"), ], [(u'a = %bc de \\', None), (u'fg\\', None), - (None, u_fmt("a = get_ipython().run_line_magic('bc', 'de fg')")), + (None, "a = get_ipython().run_line_magic('bc', 'de fg')"), ], ], assign_system = [ [(u'a = !bc de \\', None), - (u'fg', u_fmt("a = get_ipython().getoutput('bc de fg')")), + (u'fg', "a = get_ipython().getoutput('bc de fg')"), ], [(u'a = !bc de \\', None), (u'fg\\', None), - (None, u_fmt("a = get_ipython().getoutput('bc de fg')")), + (None, "a = get_ipython().getoutput('bc de fg')"), ], ], ) @@ -437,7 +429,7 @@ def test_cellmagic(): line_example = [(u'%%bar 123', None), (u'hello', None), - (u'' , u_fmt("get_ipython().run_cell_magic('bar', '123', 'hello')")), + (u'' , "get_ipython().run_cell_magic('bar', '123', 'hello')"), ] transform_checker(line_example, ipt.cellmagic, end_on_blank_line=True) @@ -475,16 +467,16 @@ def decistmt(tokens): def test_token_input_transformer(): - tests = [(u'1.2', u_fmt(u"Decimal ('1.2')")), + tests = [(u'1.2', u"Decimal ('1.2')"), (u'"1.2"', u'"1.2"'), ] tt.check_pairs(transform_and_reset(decistmt), tests) ml_tests = \ [ [(u"a = 1.2; b = '''x", None), - (u"y'''", u_fmt(u"a =Decimal ('1.2');b ='''x\ny'''")), + (u"y'''", u"a =Decimal ('1.2');b ='''x\ny'''"), ], [(u"a = [1.2,", None), - (u"3]", u_fmt(u"a =[Decimal ('1.2'),\n3 ]")), + (u"3]", u"a =[Decimal ('1.2'),\n3 ]"), ], [(u"a = '''foo", None), # Test resetting when within a multi-line string (u"bar", None), diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index c758787..62bcc91 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -39,26 +39,6 @@ def buffer_to_bytes(buf): buf = bytes(buf) return buf -def _modify_str_or_docstring(str_change_func): - @functools.wraps(str_change_func) - def wrapper(func_or_str): - if isinstance(func_or_str, (str,)): - func = None - doc = func_or_str - else: - func = func_or_str - doc = func.__doc__ - - # PYTHONOPTIMIZE=2 strips docstrings, so they can disappear unexpectedly - if doc is not None: - doc = str_change_func(doc) - - if func: - func.__doc__ = doc - return func - return doc - return wrapper - def safe_unicode(e): """unicode(e) with various fallbacks. Used for exceptions, which may not be safe to call unicode() on. @@ -167,18 +147,6 @@ def execfile(fname, glob, loc=None, compiler=None): compiler = compiler or compile exec(compiler(f.read(), fname, 'exec'), glob, loc) -# Refactor print statements in doctests. -_print_statement_re = re.compile(r"\bprint (?P.*)$", re.MULTILINE) - -# Abstract u'abc' syntax: -@_modify_str_or_docstring -def u_format(s): - """"{u}'abc'" --> "'abc'" (Python 3) - - Accepts a string or a function, so it can be used as a decorator.""" - return s.format(u='') - - PY2 = not PY3 PYPY = platform.python_implementation() == "PyPy"