combine python files (#256)

This commit is contained in:
Harrison Chase
2022-12-04 15:57:36 -08:00
committed by GitHub
parent 98fb19b535
commit f5c665a544
8 changed files with 21 additions and 76 deletions
+9 -2
View File
@@ -1,4 +1,6 @@
"""Mock Python REPL."""
import sys
from io import StringIO
from typing import Dict, Optional
@@ -10,6 +12,11 @@ class PythonREPL:
self._globals = _globals if _globals is not None else {}
self._locals = _locals if _locals is not None else {}
def run(self, command: str) -> None:
"""Run command with own globals/locals."""
def run(self, command: str) -> str:
"""Run command with own globals/locals and returns anything printed."""
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
exec(command, self._globals, self._locals)
sys.stdout = old_stdout
output = mystdout.getvalue()
return output