reuse dict for checking subset

This commit is contained in:
Jesse Bannon 2025-11-27 10:13:02 -08:00
parent b0055d59da
commit 91c45fe176
3 changed files with 10 additions and 7 deletions

View file

@ -398,8 +398,8 @@ class Script:
# 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( elif definition.is_subset_of(
variables=resolved.keys(), custom_function_definitions=self._functions variables=resolved, custom_function_definitions=self._functions
): ):
resolved[variable] = unresolved[variable].resolve( resolved[variable] = unresolved[variable].resolve(
resolved_variables=resolved, resolved_variables=resolved,

View file

@ -1,4 +1,3 @@
import copy
import functools import functools
from abc import ABC from abc import ABC
from dataclasses import dataclass from dataclasses import dataclass
@ -81,6 +80,10 @@ class CustomFunction(Function, NamedCustomFunction):
return out return out
# Implies the custom function does not exist. This should have
# been checked in the parser with
raise UNREACHABLE
class BuiltInFunction(Function, BuiltInFunctionType): class BuiltInFunction(Function, BuiltInFunctionType):
def validate_args(self) -> "BuiltInFunction": def validate_args(self) -> "BuiltInFunction":

View file

@ -162,7 +162,7 @@ class VariableDependency(ABC):
@final @final
def is_subset_of( def is_subset_of(
self, self,
variables: Iterable[Variable], variables: Dict[Variable, Resolvable],
custom_function_definitions: Dict[str, "VariableDependency"], custom_function_definitions: Dict[str, "VariableDependency"],
) -> bool: ) -> bool:
""" """
@ -171,12 +171,12 @@ class VariableDependency(ABC):
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: for custom_function in self.custom_functions:
if custom_function_definitions[custom_function.name].is_subset_of( if not custom_function_definitions[custom_function.name].is_subset_of(
variables=variables, custom_function_definitions=custom_function_definitions variables=variables, custom_function_definitions=custom_function_definitions
): ):
return True return False
return not self.variables.issubset(variables) return all(var in variables for var in self.variables)
@final @final
def contains( def contains(