Set MAX_WHILE_ITERATIONS as module variable (#520)

This commit is contained in:
Albert Villanova del Moral 2025-02-07 10:59:39 +01:00 committed by GitHub
parent c4bd41d39c
commit 8965b6a573
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 3 deletions

View File

@ -52,6 +52,7 @@ ERRORS = {
DEFAULT_MAX_LEN_OUTPUT = 50000
MAX_OPERATIONS = 10000000
MAX_WHILE_ITERATIONS = 1000000
def custom_print(*args):
@ -241,7 +242,6 @@ def evaluate_while(
custom_tools: Dict[str, Callable],
authorized_imports: List[str],
) -> None:
max_iterations = 1000000
iterations = 0
while evaluate_ast(while_loop.test, state, static_tools, custom_tools, authorized_imports):
for node in while_loop.body:
@ -252,8 +252,8 @@ def evaluate_while(
except ContinueException:
break
iterations += 1
if iterations > max_iterations:
raise InterpreterError(f"Maximum number of {max_iterations} iterations in While loop exceeded")
if iterations > MAX_WHILE_ITERATIONS:
raise InterpreterError(f"Maximum number of {MAX_WHILE_ITERATIONS} iterations in While loop exceeded")
return None