Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
import types
import warnings
from code import InteractiveConsole

from _colorize import get_theme
from _pyrepl.console import InteractiveColoredConsole
Expand All @@ -27,6 +28,11 @@ def __init__(self, locals, loop):
self.loop = loop
self.context = contextvars.copy_context()

def runsource(self, source, filename="<input>", symbol="single"):
if CAN_USE_PYREPL:
return super().runsource(source, filename, symbol)
return InteractiveConsole.runsource(self, source, filename, symbol)

def runcode(self, code):
global return_code
future = concurrent.futures.Future()
Expand Down
14 changes: 13 additions & 1 deletion Lib/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@ def f():


class TestAsyncioREPL(unittest.TestCase):
def test_multiline_support(self):
user_input = dedent("""\
async def spam():
print("eggs" + "ham")

await spam()
""")
p = spawn_repl("-m", "asyncio")
p.stdin.write(user_input)
output = kill_python(p)
self.assertIn("eggsham", output)

def test_multiple_statements_fail_early(self):
user_input = "1 / 0; print(f'afterwards: {1+1}')"
p = spawn_repl("-m", "asyncio")
Expand Down Expand Up @@ -389,7 +401,7 @@ def test_toplevel_contextvars_async(self):
""")
p = spawn_repl("-m", "asyncio")
p.stdin.write(user_input)
user_input2 = "async def set_var(): var.set('ok')\n"
user_input2 = "async def set_var(): var.set('ok')\n\n"
p.stdin.write(user_input2)
user_input3 = "await set_var()\n"
p.stdin.write(user_input3)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The :mod:`asyncio` REPL in basic mode now supports multi-line inputs. Contributed
by Bartosz Sławecki.
Loading