Skip to content

Commit

Permalink
fix(logic): setting _ is inside the runcode lock now
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Aug 10, 2024
1 parent 0cb619f commit 32ad3e7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def runsource(self, source: str, filename="<console>"):

return future

async def runcode(self, source, code):
res = await super().runcode(source, code)
if res is not None:
self.globals["__builtins__"]["_"] = res
return res


class ConsoleAPI:
def __init__(self, sync: Callable[[]]):
Expand Down Expand Up @@ -172,7 +178,6 @@ async def _():
try:
if text := await res.get_repr():
self.push_item({"type": "repr", "text": text}, behind=input_item)
self.builtins["_"] = res.future.result()
except Exception as e:
stderr = res.formatted_error or self.console.formattraceback(e)
self.push_item({"type": "err", "text": stderr, "is_traceback": True}, behind=input_item)
Expand Down

0 comments on commit 32ad3e7

Please sign in to comment.