Skip to content

Commit d8e417b

Browse files
committed
Add multi-line support to asyncio old REPL
1 parent 5f91d5d commit d8e417b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Lib/asyncio/__main__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading
1212
import types
1313
import warnings
14+
from code import InteractiveConsole
1415

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

31+
def runsource(self, source, filename="<input>", symbol="single"):
32+
if CAN_USE_PYREPL:
33+
return super().runsource(source, filename, symbol)
34+
return InteractiveConsole.runsource(self, source, filename, symbol)
35+
3036
def runcode(self, code):
3137
global return_code
3238
future = concurrent.futures.Future()

Lib/test/test_repl.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ def f():
357357

358358

359359
class TestAsyncioREPL(unittest.TestCase):
360+
def test_multiline_support(self):
361+
user_input = dedent("""\
362+
async def spam():
363+
print("eggs" + "ham")
364+
365+
await spam()
366+
""")
367+
p = spawn_repl("-m", "asyncio")
368+
p.stdin.write(user_input)
369+
output = kill_python(p)
370+
self.assertIn("eggsham", output)
371+
360372
def test_multiple_statements_fail_early(self):
361373
user_input = "1 / 0; print(f'afterwards: {1+1}')"
362374
p = spawn_repl("-m", "asyncio")
@@ -389,7 +401,7 @@ def test_toplevel_contextvars_async(self):
389401
""")
390402
p = spawn_repl("-m", "asyncio")
391403
p.stdin.write(user_input)
392-
user_input2 = "async def set_var(): var.set('ok')\n"
404+
user_input2 = "async def set_var(): var.set('ok')\n\n"
393405
p.stdin.write(user_input2)
394406
user_input3 = "await set_var()\n"
395407
p.stdin.write(user_input3)

0 commit comments

Comments
 (0)