refactor names
This commit is contained in:
parent
543845d57a
commit
3b4e1b4607
5 changed files with 10 additions and 10 deletions
|
|
@ -126,4 +126,4 @@ class Overrides(DictFormatterValidator, Scriptable):
|
||||||
if function_overrides:
|
if function_overrides:
|
||||||
script = copy.deepcopy(script).add(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))
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ class Preset(_PresetShell):
|
||||||
formatter_validator: Union[StringFormatterValidator, OverridesStringFormatterValidator],
|
formatter_validator: Union[StringFormatterValidator, OverridesStringFormatterValidator],
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
self._script.is_resolvable(
|
self._script.resolve_once(
|
||||||
formatter_validator.format_string,
|
formatter_validator.format_string,
|
||||||
unresolvable=self._get_unresolvable_variables(formatter_validator),
|
unresolvable=self._get_unresolvable_variables(formatter_validator),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -260,12 +260,12 @@ class MultiUrlValidator(OptionsValidator):
|
||||||
# Apply formatting to each new source variable, ensure it resolves
|
# Apply formatting to each new source variable, ensure it resolves
|
||||||
for collection_url in self.urls.list:
|
for collection_url in self.urls.list:
|
||||||
for name, definition in collection_url.variables.dict_with_format_strings.items():
|
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
|
# Ensure at least URL is non-empty
|
||||||
has_non_empty_url = False
|
has_non_empty_url = False
|
||||||
for url_validator in self.urls.list:
|
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:
|
if not has_non_empty_url:
|
||||||
raise self._validation_exception("Must contain at least one url that is non-empty")
|
raise self._validation_exception("Must contain at least one url that is non-empty")
|
||||||
|
|
|
||||||
|
|
@ -281,9 +281,9 @@ class Script:
|
||||||
resolved: Dict[Variable, Resolvable] = dict(
|
resolved: Dict[Variable, Resolvable] = dict(
|
||||||
# include all current variables that are resolvable
|
# include all current variables that are resolvable
|
||||||
{
|
{
|
||||||
Variable(name): ast.resolvable
|
Variable(name): ast.maybe_resolvable
|
||||||
for name, ast in self._variables.items()
|
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
|
# add explicit defined resolved variables
|
||||||
**{Variable(name): value for name, value in (resolved or {}).items()},
|
**{Variable(name): value for name, value in (resolved or {}).items()},
|
||||||
|
|
@ -357,14 +357,14 @@ class Script:
|
||||||
custom_function_names=set(self._functions.keys()),
|
custom_function_names=set(self._functions.keys()),
|
||||||
variable_names=set(self._variables.keys()).union(variables.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:
|
if not all_resolvable:
|
||||||
self._validate(added_variables=set(list(variables.keys())))
|
self._validate(added_variables=set(list(variables.keys())))
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def is_resolvable(
|
def resolve_once(
|
||||||
self,
|
self,
|
||||||
variable_definition: str,
|
variable_definition: str,
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
|
|
@ -387,7 +387,7 @@ class Script:
|
||||||
f"Tried to get resolved variable {variable_name}, but it does not exist"
|
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
|
return resolvable
|
||||||
|
|
||||||
raise RuntimeException(f"Tried to get unresolved variable {variable_name}")
|
raise RuntimeException(f"Tried to get unresolved variable {variable_name}")
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class SyntaxTree(VariableDependency):
|
||||||
return String("".join([str(res) for res in resolved]))
|
return String("".join([str(res) for res in resolved]))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def resolvable(self) -> Optional[Resolvable]:
|
def maybe_resolvable(self) -> Optional[Resolvable]:
|
||||||
if len(self.ast) == 1 and isinstance(self.ast[0], Resolvable):
|
if len(self.ast) == 1 and isinstance(self.ast[0], Resolvable):
|
||||||
return self.ast[0]
|
return self.ast[0]
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue