From 9f6be1555e2010aac9f592fee22e6de2f479cbff 2018-08-19 18:40:49 From: Matthias Bussonnier Date: 2018-08-19 18:40:49 Subject: [PATCH] att triio runner at top level now that 3.4 drop + docs --- diff --git a/IPython/core/async_helpers.py b/IPython/core/async_helpers.py index 8e6bf81..1a93d2f 100644 --- a/IPython/core/async_helpers.py +++ b/IPython/core/async_helpers.py @@ -34,22 +34,15 @@ def _curio_runner(coroutine): return curio.run(coroutine) -if sys.version_info > (3, 5): - # nose refuses to avoid this file and async def is invalidsyntax - s = dedent( - ''' - def _trio_runner(function): - import trio - async def loc(coro): - """ - We need the dummy no-op async def to protect from - trio's internal. See https://github.com/python-trio/trio/issues/89 - """ - return await coro - return trio.run(loc, function) - ''' - ) - exec(s, globals(), locals()) +def _trio_runner(function): + import trio + async def loc(coro): + """ + We need the dummy no-op async def to protect from + trio's internal. See https://github.com/python-trio/trio/issues/89 + """ + return await coro + return trio.run(loc, function) def _asyncify(code: str) -> str: diff --git a/docs/source/interactive/autoawait.rst b/docs/source/interactive/autoawait.rst index 003bf56..34f4b53 100644 --- a/docs/source/interactive/autoawait.rst +++ b/docs/source/interactive/autoawait.rst @@ -12,9 +12,10 @@ notebook interface or any other frontend using the Jupyter protocol will need to use a newer version of IPykernel. The details of how async code runs in IPykernel will differ between IPython, IPykernel and their versions. -When a supported library is used, IPython will automatically `await` Futures -and Coroutines in the REPL. This will happen if an :ref:`await ` is -use at top level scope, or if any structure valid only in `async def +When a supported library is used, IPython will automatically `await` Futures and +Coroutines in the REPL. This will happen if an :ref:`await ` (or any +other async constructs like async-with, async-for) is use at top level scope, or +if any structure valid only in `async def `_ function context are present. For example, the following being a syntax error in the Python REPL:: @@ -117,6 +118,15 @@ started only when awaited for the first time. That is to say, in first example, no network request is done between ``In[1]`` and ``In[2]``. +Effects on IPython.embed() +========================== + +IPython core being synchronous, the use of ``IPython.embed()`` will now require +a loop to run. This affect the ability to nest ``IPython.embed()`` which may +require you to install alternate IO libraries like ``curio`` and ``trio`` + + + Internals ========= diff --git a/docs/source/whatsnew/pr/await-repl.rst b/docs/source/whatsnew/pr/await-repl.rst index c8f191c..e766e74 100644 --- a/docs/source/whatsnew/pr/await-repl.rst +++ b/docs/source/whatsnew/pr/await-repl.rst @@ -63,7 +63,7 @@ Change to Nested Embed The introduction of the ability to run async code had ripple effect on the ability to use nested IPython. You may need to install the ``trio`` library -(version 05 at the time of this writing) to +(version 0.5 at the time of this writing) to have this feature working.