guydav commited on
Commit
04fec54
·
1 Parent(s): 29f937e

Experimenting with how I return results

Browse files
Files changed (1) hide show
  1. restrictedpython_code_eval.py +5 -5
restrictedpython_code_eval.py CHANGED
@@ -453,8 +453,8 @@ def _check_correctness(check_program, timeout, task_id, completion_id,
453
 
454
  out_dict = dict(
455
  task_id=task_id,
456
- passed=result[-1] == "passed",
457
- result=result[0],
458
  completion_id=completion_id,
459
  )
460
 
@@ -612,9 +612,6 @@ def _unsafe_execute(check_program, result, timeout,
612
  with time_limit(timeout):
613
  byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)
614
  exec(byte_code, exec_globals, additional_locals)
615
-
616
- if return_output:
617
- result.append(additional_locals[output_variable])
618
 
619
  result.append("passed")
620
 
@@ -626,6 +623,9 @@ def _unsafe_execute(check_program, result, timeout,
626
  result.append(f"failed ({type(e)}): {str(e)}")
627
  result.append(e)
628
 
 
 
 
629
  # Needed for cleaning up.
630
  shutil.rmtree = rmtree
631
  os.rmdir = rmdir
 
453
 
454
  out_dict = dict(
455
  task_id=task_id,
456
+ passed=result[0] == "passed",
457
+ result=result,
458
  completion_id=completion_id,
459
  )
460
 
 
612
  with time_limit(timeout):
613
  byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)
614
  exec(byte_code, exec_globals, additional_locals)
 
 
 
615
 
616
  result.append("passed")
617
 
 
623
  result.append(f"failed ({type(e)}): {str(e)}")
624
  result.append(e)
625
 
626
+ if return_output and output_variable in additional_locals: # type: ignore
627
+ result.append(additional_locals[output_variable]) # type: ignore
628
+
629
  # Needed for cleaning up.
630
  shutil.rmtree = rmtree
631
  os.rmdir = rmdir