From 422664acd4c9d47fb2164710afcc7489ea94e332 2018-08-27 13:52:31 From: Paul Ganssle Date: 2018-08-27 13:52:31 Subject: [PATCH] Fix indentation problem with _asyncify If the input to `_asyncify` contains newlines, the strategy of indenting and then truncating the first 8 characters won't work, since the first, empty line doesn't get indented. Instead I've changed the format string to accept the normal output of textwrap.indent() without modification. --- diff --git a/IPython/core/async_helpers.py b/IPython/core/async_helpers.py index fa3d5cf..e8096e0 100644 --- a/IPython/core/async_helpers.py +++ b/IPython/core/async_helpers.py @@ -69,14 +69,14 @@ def _asyncify(code: str) -> str: And setup a bit of context to run it later. """ res = dedent( - """ - async def __wrapper__(): - try: - {usercode} - finally: - locals() """ - ).format(usercode=indent(code, " " * 8)[8:]) + async def __wrapper__(): + try: + {usercode} + finally: + locals() + """ + ).format(usercode=indent(code, " " * 8)) return res