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:
|
||||
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],
|
||||
) -> None:
|
||||
try:
|
||||
self._script.is_resolvable(
|
||||
self._script.resolve_once(
|
||||
formatter_validator.format_string,
|
||||
unresolvable=self._get_unresolvable_variables(formatter_validator),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue