factor out mock python repl (#43)

This commit is contained in:
Harrison Chase
2022-10-30 18:09:04 -07:00
committed by GitHub
parent 7b0d02ac51
commit fba30e07d1
3 changed files with 52 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
"""Mock Python REPL."""
from typing import Dict, Optional
class PythonREPL:
"""Simulates a standalone Python REPL."""
def __init__(self, _globals: Optional[Dict] = None, _locals: Optional[Dict] = None):
"""Initialize with optional globals and locals."""
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."""
exec(command, self._globals, self._locals)