fix custom func dep bug
This commit is contained in:
parent
904e52c4f5
commit
c122e535c1
4 changed files with 34 additions and 16 deletions
|
|
@ -151,8 +151,9 @@ class Script:
|
|||
return
|
||||
|
||||
lambda_function_names = set(
|
||||
lamb.value for lamb in SyntaxTree(function.args).lambdas if isinstance(lamb, Lambda)
|
||||
and lamb in function.args
|
||||
lamb.value
|
||||
for lamb in SyntaxTree(function.args).lambdas
|
||||
if isinstance(lamb, Lambda) and lamb in function.args
|
||||
)
|
||||
|
||||
# Only case len(lambda_function_names) > 1 is when used in if-statements
|
||||
|
|
@ -367,13 +368,15 @@ class Script:
|
|||
|
||||
# If the variable's variable dependencies contain an unresolvable variable,
|
||||
# declare it as unresolvable and continue
|
||||
elif definition.contains(unresolvable):
|
||||
elif definition.contains(unresolvable, custom_function_definitions=self._functions):
|
||||
unresolvable.add(variable)
|
||||
del unresolved[variable]
|
||||
|
||||
# Otherwise, if it has dependencies that are all resolved, then
|
||||
# resolve the definition
|
||||
elif not definition.is_subset_of(variables=resolved.keys()):
|
||||
elif not definition.is_subset_of(
|
||||
variables=resolved.keys(), custom_function_definitions=self._functions
|
||||
):
|
||||
resolved[variable] = unresolved[variable].resolve(
|
||||
resolved_variables=resolved,
|
||||
custom_functions=self._functions,
|
||||
|
|
|
|||
|
|
@ -156,19 +156,38 @@ class VariableDependency(ABC):
|
|||
raise UNREACHABLE
|
||||
|
||||
@final
|
||||
def is_subset_of(self, variables: Iterable[Variable]) -> bool:
|
||||
def is_subset_of(
|
||||
self,
|
||||
variables: Iterable[Variable],
|
||||
custom_function_definitions: Dict[str, "VariableDependency"],
|
||||
) -> bool:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
True if it contains all input variables as a dependency. False otherwise.
|
||||
"""
|
||||
for custom_function in self.custom_functions:
|
||||
if custom_function_definitions[custom_function.name].is_subset_of(
|
||||
variables=variables, custom_function_definitions=custom_function_definitions
|
||||
):
|
||||
return True
|
||||
|
||||
return not self.variables.issubset(variables)
|
||||
|
||||
@final
|
||||
def contains(self, variables: Iterable[Variable]) -> bool:
|
||||
def contains(
|
||||
self,
|
||||
variables: Iterable[Variable],
|
||||
custom_function_definitions: Dict[str, "VariableDependency"],
|
||||
) -> bool:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
True if it contains any of the input variables. False otherwise.
|
||||
"""
|
||||
for custom_function in self.custom_functions:
|
||||
if custom_function_definitions[custom_function.name].contains(
|
||||
variables=variables, custom_function_definitions=custom_function_definitions
|
||||
):
|
||||
return True
|
||||
return len(self.variables.intersection(variables)) > 0
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ from ytdl_sub.script.types.array import UnresolvedArray
|
|||
from ytdl_sub.script.types.function import BuiltInFunction
|
||||
from ytdl_sub.script.types.function import Function
|
||||
from ytdl_sub.script.types.map import UnresolvedMap
|
||||
from ytdl_sub.script.types.resolvable import Argument, Lambda
|
||||
from ytdl_sub.script.types.resolvable import Argument
|
||||
from ytdl_sub.script.types.resolvable import Boolean
|
||||
from ytdl_sub.script.types.resolvable import Float
|
||||
from ytdl_sub.script.types.resolvable import Integer
|
||||
from ytdl_sub.script.types.resolvable import Lambda
|
||||
from ytdl_sub.script.types.resolvable import String
|
||||
from ytdl_sub.script.types.variable import Variable
|
||||
from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
||||
|
|
|
|||
|
|
@ -550,17 +550,12 @@ class TestPrebuiltMusicVideoPresets:
|
|||
album_metadata: str,
|
||||
multi_url: bool,
|
||||
) -> Dict:
|
||||
subscription_dict = {
|
||||
album_metadata: [
|
||||
"https://your.name.here"
|
||||
]
|
||||
}
|
||||
subscription_dict = {album_metadata: ["https://your.name.here"]}
|
||||
|
||||
if multi_url:
|
||||
subscription_dict[album_metadata].append({
|
||||
"url": "https://your.name.here2",
|
||||
"title": "Custom Title"
|
||||
})
|
||||
subscription_dict[album_metadata].append(
|
||||
{"url": "https://your.name.here2", "title": "Custom Title"}
|
||||
)
|
||||
|
||||
preset_dict = {
|
||||
"preset": [
|
||||
|
|
|
|||
Loading…
Reference in a new issue