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
|
return
|
||||||
|
|
||||||
lambda_function_names = set(
|
lambda_function_names = set(
|
||||||
lamb.value for lamb in SyntaxTree(function.args).lambdas if isinstance(lamb, Lambda)
|
lamb.value
|
||||||
and lamb in function.args
|
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
|
# 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,
|
# If the variable's variable dependencies contain an unresolvable variable,
|
||||||
# declare it as unresolvable and continue
|
# declare it as unresolvable and continue
|
||||||
elif definition.contains(unresolvable):
|
elif definition.contains(unresolvable, custom_function_definitions=self._functions):
|
||||||
unresolvable.add(variable)
|
unresolvable.add(variable)
|
||||||
del unresolved[variable]
|
del unresolved[variable]
|
||||||
|
|
||||||
# Otherwise, if it has dependencies that are all resolved, then
|
# Otherwise, if it has dependencies that are all resolved, then
|
||||||
# resolve the definition
|
# 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[variable] = unresolved[variable].resolve(
|
||||||
resolved_variables=resolved,
|
resolved_variables=resolved,
|
||||||
custom_functions=self._functions,
|
custom_functions=self._functions,
|
||||||
|
|
|
||||||
|
|
@ -156,19 +156,38 @@ class VariableDependency(ABC):
|
||||||
raise UNREACHABLE
|
raise UNREACHABLE
|
||||||
|
|
||||||
@final
|
@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
|
Returns
|
||||||
-------
|
-------
|
||||||
True if it contains all input variables as a dependency. False otherwise.
|
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)
|
return not self.variables.issubset(variables)
|
||||||
|
|
||||||
@final
|
@final
|
||||||
def contains(self, variables: Iterable[Variable]) -> bool:
|
def contains(
|
||||||
|
self,
|
||||||
|
variables: Iterable[Variable],
|
||||||
|
custom_function_definitions: Dict[str, "VariableDependency"],
|
||||||
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
True if it contains any of the input variables. False otherwise.
|
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
|
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 BuiltInFunction
|
||||||
from ytdl_sub.script.types.function import Function
|
from ytdl_sub.script.types.function import Function
|
||||||
from ytdl_sub.script.types.map import UnresolvedMap
|
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 Boolean
|
||||||
from ytdl_sub.script.types.resolvable import Float
|
from ytdl_sub.script.types.resolvable import Float
|
||||||
from ytdl_sub.script.types.resolvable import Integer
|
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.resolvable import String
|
||||||
from ytdl_sub.script.types.variable import Variable
|
from ytdl_sub.script.types.variable import Variable
|
||||||
from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
||||||
|
|
|
||||||
|
|
@ -550,17 +550,12 @@ class TestPrebuiltMusicVideoPresets:
|
||||||
album_metadata: str,
|
album_metadata: str,
|
||||||
multi_url: bool,
|
multi_url: bool,
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
subscription_dict = {
|
subscription_dict = {album_metadata: ["https://your.name.here"]}
|
||||||
album_metadata: [
|
|
||||||
"https://your.name.here"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
if multi_url:
|
if multi_url:
|
||||||
subscription_dict[album_metadata].append({
|
subscription_dict[album_metadata].append(
|
||||||
"url": "https://your.name.here2",
|
{"url": "https://your.name.here2", "title": "Custom Title"}
|
||||||
"title": "Custom Title"
|
)
|
||||||
})
|
|
||||||
|
|
||||||
preset_dict = {
|
preset_dict = {
|
||||||
"preset": [
|
"preset": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue