Fix execute_processing_script to support list comprehensions
The exec() function was using empty globals dict which prevented list comprehensions from accessing variables in the local scope. Changed to use the same dict for both globals and locals to properly support comprehensions in processing scripts. Fixes battleship game flow tests that use list comprehensions.
This commit is contained in:
parent
803cdb0a0f
commit
34c48743d0
2 changed files with 15 additions and 8 deletions
10
activity.py
10
activity.py
|
|
@ -372,17 +372,19 @@ def display_activity_metadata(room_name, username):
|
|||
|
||||
|
||||
def execute_processing_script(metadata, script):
|
||||
# Prepare the local environment for the script
|
||||
local_env = {
|
||||
# Prepare the environment for the script
|
||||
# Use the same dict for both globals and locals to support comprehensions
|
||||
script_env = {
|
||||
"__builtins__": __builtins__,
|
||||
"metadata": metadata,
|
||||
"script_result": None,
|
||||
}
|
||||
|
||||
# Execute the script
|
||||
exec(script, {}, local_env)
|
||||
exec(script, script_env, script_env)
|
||||
|
||||
# Return the result from the script
|
||||
return local_env["script_result"]
|
||||
return script_env["script_result"]
|
||||
|
||||
|
||||
def handle_activity_response(room_name, user_response, username, model="MODEL_0"):
|
||||
|
|
|
|||
|
|
@ -297,14 +297,19 @@ def provide_feedback_prompts(
|
|||
|
||||
|
||||
def execute_processing_script(metadata, script):
|
||||
# Prepare the local environment for the script
|
||||
local_env = {"metadata": metadata, "script_result": None}
|
||||
# Prepare the environment for the script
|
||||
# Use the same dict for both globals and locals to support comprehensions
|
||||
script_env = {
|
||||
"__builtins__": __builtins__,
|
||||
"metadata": metadata,
|
||||
"script_result": None,
|
||||
}
|
||||
|
||||
# Execute the script
|
||||
exec(script, {}, local_env)
|
||||
exec(script, script_env, script_env)
|
||||
|
||||
# Return the result from the script
|
||||
return local_env["script_result"]
|
||||
return script_env["script_result"]
|
||||
|
||||
|
||||
def get_next_section_and_step(activity_content, current_section_id, current_step_id):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue