valiant21 commited on
Commit
0410277
·
verified ·
1 Parent(s): 2c47baa

Function allowance to interpretable

Browse files
Files changed (1) hide show
  1. interpreter.py +5 -2
interpreter.py CHANGED
@@ -18,6 +18,9 @@ def run_code(code):
18
  old_stdout = sys.stdout
19
  redirected_output = sys.stdout = io.StringIO()
20
 
 
 
 
21
  try:
22
  # Parse the code to detect function definitions
23
  tree = ast.parse(code)
@@ -25,8 +28,8 @@ def run_code(code):
25
  node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)
26
  ]
27
 
28
- # Execute the code
29
- exec(code)
30
 
31
  # Check if functions are defined but not called
32
  if function_names:
 
18
  old_stdout = sys.stdout
19
  redirected_output = sys.stdout = io.StringIO()
20
 
21
+ # Create a dedicated execution namespace
22
+ exec_globals = {}
23
+
24
  try:
25
  # Parse the code to detect function definitions
26
  tree = ast.parse(code)
 
28
  node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)
29
  ]
30
 
31
+ # Execute the code in the dedicated namespace
32
+ exec(code, exec_globals)
33
 
34
  # Check if functions are defined but not called
35
  if function_names: