more simplifying

This commit is contained in:
Jesse Bannon 2026-01-12 17:04:56 -08:00
parent 26c2045a74
commit 3d40dce97c
2 changed files with 10 additions and 21 deletions

View file

@ -4,6 +4,7 @@ from dataclasses import dataclass
from typing import Callable from typing import Callable
from typing import Dict from typing import Dict
from typing import List from typing import List
from typing import Optional
from typing import Type from typing import Type
from typing import Union from typing import Union
@ -422,8 +423,7 @@ class BuiltInFunction(Function, BuiltInFunctionType):
resolved_variables: Dict[Variable, Resolvable], resolved_variables: Dict[Variable, Resolvable],
unresolved_variables: Dict[Variable, Argument], unresolved_variables: Dict[Variable, Argument],
custom_functions: Dict[str, "VariableDependency"], custom_functions: Dict[str, "VariableDependency"],
) -> Argument: ) -> Optional[Argument]:
# TODO: arg optimization
if self.name == "array_at": if self.name == "array_at":
if ( if (
isinstance(self.args[0], UnresolvedArray) isinstance(self.args[0], UnresolvedArray)

View file

@ -258,25 +258,22 @@ class VariableDependency(ABC):
Attempts to resolve a list of arguments. Returns a tuple of them post partially resolved, Attempts to resolve a list of arguments. Returns a tuple of them post partially resolved,
and a boolean indicating whether all of them are fully resolved. and a boolean indicating whether all of them are fully resolved.
""" """
maybe_resolvable_args: List[Resolvable | Argument | "VariableDependency"] = [] maybe_resolvable_args: List[Argument] = []
is_resolvable = True is_resolvable = True
for arg in args: for arg in args:
if isinstance(arg, Lambda) and arg.value in custom_functions: maybe_resolvable_args.append(arg)
maybe_resolvable_args.append(arg)
if isinstance(arg, Lambda) and arg.value in custom_functions:
if not custom_functions[arg.value].is_subset_of( if not custom_functions[arg.value].is_subset_of(
variables=resolved_variables, variables=resolved_variables,
custom_function_definitions=custom_functions, custom_function_definitions=custom_functions,
): ):
is_resolvable = False is_resolvable = False
elif isinstance(arg, VariableDependency): elif isinstance(arg, VariableDependency):
maybe_resolvable_args.append( maybe_resolvable_args[-1] = arg.partial_resolve(
arg.partial_resolve( resolved_variables=resolved_variables,
resolved_variables=resolved_variables, unresolved_variables=unresolved_variables,
unresolved_variables=unresolved_variables, custom_functions=custom_functions,
custom_functions=custom_functions,
)
) )
if not isinstance(maybe_resolvable_args[-1], Resolvable): if not isinstance(maybe_resolvable_args[-1], Resolvable):
@ -284,15 +281,7 @@ class VariableDependency(ABC):
elif isinstance(arg, Variable): elif isinstance(arg, Variable):
if arg not in resolved_variables: if arg not in resolved_variables:
is_resolvable = False is_resolvable = False
if arg in unresolved_variables: if arg in unresolved_variables:
maybe_resolvable_args.append(unresolved_variables[arg]) maybe_resolvable_args[-1] = unresolved_variables[arg]
else:
# Must be unresolvable
maybe_resolvable_args.append(arg)
else:
maybe_resolvable_args.append(arg)
else:
maybe_resolvable_args.append(arg)
return maybe_resolvable_args, is_resolvable return maybe_resolvable_args, is_resolvable