diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 1196b0d..267b73a 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -24,6 +24,7 @@ import sys import tokenize import warnings +from IPython.utils.py3compat import cast_unicode from IPython.core.inputtransformer import (leading_indent, classic_prompt, ipy_prompt, @@ -686,6 +687,7 @@ class IPythonInputSplitter(InputSplitter): """ # We must ensure all input is pure unicode + lines = cast_unicode(lines, self.encoding) # ''.splitlines() --> [], but we need to push the empty line to transformers lines_list = lines.splitlines() if not lines_list: diff --git a/docs/source/config/inputtransforms.rst b/docs/source/config/inputtransforms.rst index aa04e7e..4bff5b5 100644 --- a/docs/source/config/inputtransforms.rst +++ b/docs/source/config/inputtransforms.rst @@ -74,6 +74,13 @@ function. Transforming a full block ------------------------- +.. warning:: + + Transforming a full block at once will break the automatic detection of + wether a block of code is complete in interface relying on this + functionality, as for example terminal IPython. You will need to use a + shortcut to force-execute your cells. + Transforming a full block of python code is possible by implementing a :class:`~IPython.core.inputtransformer.Inputtransformer` and overwriting the ``push`` and ``reset`` methods. The reset method should send the full block of @@ -108,9 +115,11 @@ should give up any code it has accumulated. You may use :meth:`CoroutineInputTransformer.wrap` to simplify the creation of such a transformer. -Here is a simple :class:`CoroutineInputTransformer` that can be though of be +Here is a simple :class:`CoroutineInputTransformer` that can be thought of being the identity:: + from IPython.core.inputtransformer import CoroutineInputTransformer + @CoroutineInputTransformer.wrap def noop(): line = ''