Skip to content

aiorepl: Replace f-string with str.format. #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2023
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
aiorepl: Replace f-string with str.format.
f-strings aren't enabled on all builds (e.g. low-flash ESP8266).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <[email protected]>
  • Loading branch information
jimmo authored and dpgeorge committed Jul 21, 2023
commit ff842310de5a3c9ea5a5aa5cbaa52e06e5f2952b
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