Skip to content
Merged
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
16 changes: 9 additions & 7 deletions micropython/aiorepl/aiorepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ async def execute(code, g, s):
if "await " in code:
# Execute the code snippet in an async context.
if m := _RE_IMPORT.match(code) or _RE_FROM_IMPORT.match(code):
code = f"global {m.group(3) or m.group(1)}\n {code}"
code = "global {}\n {}".format(m.group(3) or m.group(1), code)
elif m := _RE_GLOBAL.match(code):
code = f"global {m.group(1)}\n {code}"
code = "global {}\n {}".format(m.group(1), code)
elif not _RE_ASSIGN.search(code):
code = f"return {code}"
code = "return {}".format(code)

code = f"""
code = """
import uasyncio as asyncio
async def __code():
{code}
{}

__exec_task = asyncio.create_task(__code())
"""
""".format(
code
)

async def kbd_intr_task(exec_task, s):
while True:
Expand Down Expand Up @@ -81,7 +83,7 @@ async def kbd_intr_task(exec_task, s):
micropython.kbd_intr(-1)

except Exception as err:
print(f"{type(err).__name__}: {err}")
print("{}: {}".format(type(err).__name__, err))


# REPL task. Invoke this with an optional mutable globals dict.
Expand Down