Spaces:
Runtime error
Runtime error
Updated `return_output` logic
Browse files524 unmodified lines5255265275285285295305 unmodified lines53653753854054154253954054160 unmodified lines6026036046056066076086096106116126146136146156165 unmodified lines622623624626627625626627628629524 unmodified lines allow_underscore_variable_names: bool = False, return_output: bool = False, output_variable: str = "output"):
with create_tempdir():
# These system calls are needed when cleaning up tempdir. import os import shutil5 unmodified lines # Disable functionalities that can make destructive changes to the test. reliability_guard()
if return_output and additional_locals is None: additional_locals = {}
# Run program. try: builtins = {}60 unmodified lines if '_apply_' not in exec_globals: exec_globals['_apply_'] = _apply # type: ignore
if additional_locals is not None: additional_globals.update(additional_locals)
with swallow_io(): policy_class = AllowAugmentedAssignAndUnderscoreVariableNamesRestrictingTransformer if allow_underscore_variable_names else AllowAugmentedAssignRestrictingTransformer
with time_limit(timeout): byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class) exec(byte_code, exec_globals, additional_locals) exec(byte_code, exec_globals, None) result['result'] = "passed"
5 unmodified lines result['result'] = f"failed ({type(e)}): {str(e)}" result['exception'] = e
if return_output and output_variable in additional_locals: # type: ignore result[output_variable] = additional_locals[output_variable] # type: ignore if return_output and output_variable in exec_globals: # type: ignore result[output_variable] = exec_globals[output_variable] # type: ignore
# Needed for cleaning up. shutil.rmtree = rmtreerestrictedpython_code_eval.py+6-7