From 3d40dce97c41aa8f6082bee525464409a15cc8a6 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Mon, 12 Jan 2026 17:04:56 -0800 Subject: [PATCH] more simplifying --- src/ytdl_sub/script/types/function.py | 4 +-- .../script/types/variable_dependency.py | 27 ++++++------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/ytdl_sub/script/types/function.py b/src/ytdl_sub/script/types/function.py index ed7f441d..aedeff59 100644 --- a/src/ytdl_sub/script/types/function.py +++ b/src/ytdl_sub/script/types/function.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from typing import Callable from typing import Dict from typing import List +from typing import Optional from typing import Type from typing import Union @@ -422,8 +423,7 @@ class BuiltInFunction(Function, BuiltInFunctionType): resolved_variables: Dict[Variable, Resolvable], unresolved_variables: Dict[Variable, Argument], custom_functions: Dict[str, "VariableDependency"], - ) -> Argument: - # TODO: arg optimization + ) -> Optional[Argument]: if self.name == "array_at": if ( isinstance(self.args[0], UnresolvedArray) diff --git a/src/ytdl_sub/script/types/variable_dependency.py b/src/ytdl_sub/script/types/variable_dependency.py index 1101be8e..5cfee863 100644 --- a/src/ytdl_sub/script/types/variable_dependency.py +++ b/src/ytdl_sub/script/types/variable_dependency.py @@ -258,25 +258,22 @@ class VariableDependency(ABC): Attempts to resolve a list of arguments. Returns a tuple of them post partially resolved, and a boolean indicating whether all of them are fully resolved. """ - maybe_resolvable_args: List[Resolvable | Argument | "VariableDependency"] = [] + maybe_resolvable_args: List[Argument] = [] is_resolvable = True for arg in args: - if isinstance(arg, Lambda) and arg.value in custom_functions: - maybe_resolvable_args.append(arg) + maybe_resolvable_args.append(arg) + if isinstance(arg, Lambda) and arg.value in custom_functions: if not custom_functions[arg.value].is_subset_of( variables=resolved_variables, custom_function_definitions=custom_functions, ): is_resolvable = False - elif isinstance(arg, VariableDependency): - maybe_resolvable_args.append( - arg.partial_resolve( - resolved_variables=resolved_variables, - unresolved_variables=unresolved_variables, - custom_functions=custom_functions, - ) + maybe_resolvable_args[-1] = arg.partial_resolve( + resolved_variables=resolved_variables, + unresolved_variables=unresolved_variables, + custom_functions=custom_functions, ) if not isinstance(maybe_resolvable_args[-1], Resolvable): @@ -284,15 +281,7 @@ class VariableDependency(ABC): elif isinstance(arg, Variable): if arg not in resolved_variables: is_resolvable = False - if arg in unresolved_variables: - maybe_resolvable_args.append(unresolved_variables[arg]) - else: - # Must be unresolvable - maybe_resolvable_args.append(arg) - else: - maybe_resolvable_args.append(arg) - else: - maybe_resolvable_args.append(arg) + maybe_resolvable_args[-1] = unresolved_variables[arg] return maybe_resolvable_args, is_resolvable