From f4c8405dc2768ac2818d639479d1817b71102b08 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Wed, 31 Dec 2025 00:01:39 -0800 Subject: [PATCH] [BUGFIX] Fix custom function lambda cycle detection --- src/ytdl_sub/script/script.py | 15 +++++++++++++++ src/ytdl_sub/script/types/variable_dependency.py | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ytdl_sub/script/script.py b/src/ytdl_sub/script/script.py index b4c431df..54cd3c3b 100644 --- a/src/ytdl_sub/script/script.py +++ b/src/ytdl_sub/script/script.py @@ -66,6 +66,21 @@ class Script: deps=deps + [dep.name], ) + for custom_func in variable_dependency.custom_function_dependencies( + custom_function_definitions=self._functions + ): + for dep in self._functions[custom_func.name].variables: + self._ensure_no_cycle( + name=variable_name, dep=dep.name, deps=deps, definitions=self._variables + ) + self._traverse_variable_dependencies( + variable_name=variable_name, + variable_dependency=self._variables[dep.name], + deps=deps + [dep.name], + ) + + + def _ensure_no_variable_cycles(self, variables: Dict[str, SyntaxTree]): for variable_name, variable_definition in variables.items(): self._traverse_variable_dependencies( diff --git a/src/ytdl_sub/script/types/variable_dependency.py b/src/ytdl_sub/script/types/variable_dependency.py index 18f2dab2..6025dfea 100644 --- a/src/ytdl_sub/script/types/variable_dependency.py +++ b/src/ytdl_sub/script/types/variable_dependency.py @@ -160,7 +160,7 @@ class VariableDependency(ABC): raise UNREACHABLE @final - def _custom_function_dependencies( + def custom_function_dependencies( self, custom_function_definitions: Dict[str, "VariableDependency"] ) -> Set[ParsedCustomFunction]: custom_functions = self.custom_functions @@ -185,7 +185,7 @@ class VariableDependency(ABC): True if it contains all input variables as a dependency. False otherwise. """ # If there are lambdas, see if they are custom functions. If so, check them - for custom_function in self._custom_function_dependencies(custom_function_definitions): + for custom_function in self.custom_function_dependencies(custom_function_definitions): if not custom_function_definitions[custom_function.name].is_subset_of( variables=variables, custom_function_definitions=custom_function_definitions ): @@ -205,7 +205,7 @@ class VariableDependency(ABC): True if it contains any of the input variables. False otherwise. """ # If there are lambdas, see if they are custom functions. If so, check them - for custom_function in self._custom_function_dependencies(custom_function_definitions): + for custom_function in self.custom_function_dependencies(custom_function_definitions): if custom_function_definitions[custom_function.name].contains( variables=variables, custom_function_definitions=custom_function_definitions ):