diff --git a/src/ytdl_sub/config/overrides.py b/src/ytdl_sub/config/overrides.py index e4dd4c92..36fe785f 100644 --- a/src/ytdl_sub/config/overrides.py +++ b/src/ytdl_sub/config/overrides.py @@ -126,4 +126,4 @@ class Overrides(DictFormatterValidator, Scriptable): if function_overrides: script = copy.deepcopy(script).add(function_overrides) - return str(script.is_resolvable(formatter.format_string, unresolvable=unresolvable)) + return str(script.resolve_once(formatter.format_string, unresolvable=unresolvable)) diff --git a/src/ytdl_sub/config/preset.py b/src/ytdl_sub/config/preset.py index e666b68c..92a8bb8d 100644 --- a/src/ytdl_sub/config/preset.py +++ b/src/ytdl_sub/config/preset.py @@ -258,7 +258,7 @@ class Preset(_PresetShell): formatter_validator: Union[StringFormatterValidator, OverridesStringFormatterValidator], ) -> None: try: - self._script.is_resolvable( + self._script.resolve_once( formatter_validator.format_string, unresolvable=self._get_unresolvable_variables(formatter_validator), ) diff --git a/src/ytdl_sub/downloaders/url/validators.py b/src/ytdl_sub/downloaders/url/validators.py index 5e431f20..63f5b2b9 100644 --- a/src/ytdl_sub/downloaders/url/validators.py +++ b/src/ytdl_sub/downloaders/url/validators.py @@ -260,12 +260,12 @@ class MultiUrlValidator(OptionsValidator): # Apply formatting to each new source variable, ensure it resolves for collection_url in self.urls.list: for name, definition in collection_url.variables.dict_with_format_strings.items(): - script.is_resolvable(variable_name=name, variable_definition=definition) + script.resolve_once(variable_name=name, variable_definition=definition) # Ensure at least URL is non-empty has_non_empty_url = False for url_validator in self.urls.list: - has_non_empty_url |= bool(str(script.is_resolvable(url_validator.url.format_string))) + has_non_empty_url |= bool(str(script.resolve_once(url_validator.url.format_string))) if not has_non_empty_url: raise self._validation_exception("Must contain at least one url that is non-empty") diff --git a/src/ytdl_sub/script/script.py b/src/ytdl_sub/script/script.py index f0d82e65..4b5d01b9 100644 --- a/src/ytdl_sub/script/script.py +++ b/src/ytdl_sub/script/script.py @@ -281,9 +281,9 @@ class Script: resolved: Dict[Variable, Resolvable] = dict( # include all current variables that are resolvable { - Variable(name): ast.resolvable + Variable(name): ast.maybe_resolvable for name, ast in self._variables.items() - if ast.resolvable is not None + if ast.maybe_resolvable is not None }, # add explicit defined resolved variables **{Variable(name): value for name, value in (resolved or {}).items()}, @@ -357,14 +357,14 @@ class Script: custom_function_names=set(self._functions.keys()), variable_names=set(self._variables.keys()).union(variables.keys()), ) - all_resolvable &= self._variables[variable_name].resolvable is not None + all_resolvable &= self._variables[variable_name].maybe_resolvable is not None if not all_resolvable: self._validate(added_variables=set(list(variables.keys()))) return self - def is_resolvable( + def resolve_once( self, variable_definition: str, variable_name: Optional[str] = None, @@ -387,7 +387,7 @@ class Script: f"Tried to get resolved variable {variable_name}, but it does not exist" ) - if (resolvable := self._variables[variable_name].resolvable) is not None: + if (resolvable := self._variables[variable_name].maybe_resolvable) is not None: return resolvable raise RuntimeException(f"Tried to get unresolved variable {variable_name}") diff --git a/src/ytdl_sub/script/types/syntax_tree.py b/src/ytdl_sub/script/types/syntax_tree.py index d2797246..b6092c34 100644 --- a/src/ytdl_sub/script/types/syntax_tree.py +++ b/src/ytdl_sub/script/types/syntax_tree.py @@ -41,7 +41,7 @@ class SyntaxTree(VariableDependency): return String("".join([str(res) for res in resolved])) @property - def resolvable(self) -> Optional[Resolvable]: + def maybe_resolvable(self) -> Optional[Resolvable]: if len(self.ast) == 1 and isinstance(self.ast[0], Resolvable): return self.ast[0] return None