Spaces:
Runtime error
Runtime error
Updated `return_output` logic
Browse files524 unmodified lines5255265275285295305315 unmodified lines53753853954054154254354454560 unmodified lines6066076086096106116126136146156166175 unmodified lines623624625626627628629630524 unmodified linesallow_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 osimport 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 linesif '_apply_' not in exec_globals:exec_globals['_apply_'] = _apply # type: ignorewith swallow_io():policy_class = AllowAugmentedAssignAndUnderscoreVariableNamesRestrictingTransformer if allow_underscore_variable_names else AllowAugmentedAssignRestrictingTransformerwith time_limit(timeout):byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)exec(byte_code, exec_globals, additional_locals)result['result'] = "passed"5 unmodified linesresult['result'] = f"failed ({type(e)}): {str(e)}"result['exception'] = eif return_output and output_variable in additional_locals: # type: ignoreresult[output_variable] = additional_locals[output_variable] # type: ignore# Needed for cleaning up.shutil.rmtree = rmtree524 unmodified lines5255265275285295305 unmodified lines53653753853954054160 unmodified lines6026036046056066076086096106116126136146156165 unmodified lines622623624625626627628629524 unmodified linesallow_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 osimport shutil5 unmodified lines# Disable functionalities that can make destructive changes to the test.reliability_guard()# Run program.try:builtins = {}60 unmodified linesif '_apply_' not in exec_globals:exec_globals['_apply_'] = _apply # type: ignoreif additional_locals is not None:additional_globals.update(additional_locals)with swallow_io():policy_class = AllowAugmentedAssignAndUnderscoreVariableNamesRestrictingTransformer if allow_underscore_variable_names else AllowAugmentedAssignRestrictingTransformerwith time_limit(timeout):byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)exec(byte_code, exec_globals, None)result['result'] = "passed"5 unmodified linesresult['result'] = f"failed ({type(e)}): {str(e)}"result['exception'] = eif return_output and output_variable in exec_globals: # type: ignoreresult[output_variable] = exec_globals[output_variable] # type: ignore# Needed for cleaning up.shutil.rmtree = rmtree
restrictedpython_code_eval.py+6-7