From 341c046c7ce22c633daf3cb12f3f439c6f376056 2014-01-10 01:13:21 From: Thomas Kluyver Date: 2014-01-10 01:13:21 Subject: [PATCH] Backport PR #4758 - fixes for Python 3.4. --- diff --git a/IPython/utils/tests/test_text.py b/IPython/utils/tests/test_text.py index 5803a85..d1cc5f5 100644 --- a/IPython/utils/tests/test_text.py +++ b/IPython/utils/tests/test_text.py @@ -15,6 +15,7 @@ import os import math import random +import sys import nose.tools as nt @@ -107,7 +108,12 @@ def eval_formatter_no_slicing_check(f): s = f.format('{stuff[slice(1,4)]}', **ns) nt.assert_equal(s, 'ell') - nt.assert_raises(SyntaxError, f.format, "{a[:]}") + if sys.version_info >= (3, 4): + # String formatting has changed in Python 3.4, so this now works. + s = f.format("{a[:]}", a=[1, 2]) + nt.assert_equal(s, "[1, 2]") + else: + nt.assert_raises(SyntaxError, f.format, "{a[:]}") def test_eval_formatter(): f = text.EvalFormatter() diff --git a/IPython/utils/text.py b/IPython/utils/text.py index c20d2f5..5cfce4b 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -509,6 +509,9 @@ class EvalFormatter(Formatter): v = eval(name, kwargs) return v, name +#XXX: As of Python 3.4, the format string parsing no longer splits on a colon +# inside [], so EvalFormatter can handle slicing. Once we only support 3.4 and +# above, it should be possible to remove FullEvalFormatter. @skip_doctest_py3 class FullEvalFormatter(Formatter):