Merge branch 'master' into j/array-url-support

This commit is contained in:
Jesse Bannon 2025-12-30 20:02:53 -08:00
commit 131aedfd60
2 changed files with 34 additions and 1 deletions

View file

@ -114,6 +114,7 @@ class VariableDependency(ABC):
output.add(ParsedCustomFunction(name=arg.name, num_input_args=len(arg.args))) output.add(ParsedCustomFunction(name=arg.name, num_input_args=len(arg.args)))
if isinstance(arg, VariableDependency): if isinstance(arg, VariableDependency):
output.update(arg.custom_functions) output.update(arg.custom_functions)
# if isinstance(arg, Lambda)
return output return output
@ -189,7 +190,17 @@ class VariableDependency(ABC):
------- -------
True if it contains any of the input variables. False otherwise. True if it contains any of the input variables. False otherwise.
""" """
for custom_function in self.custom_functions: # If there are lambdas, see if they are custom functions. If so, check them
custom_functions_to_check = self.custom_functions
for lambda_func in self.lambdas:
if lambda_func.value in custom_function_definitions:
custom_functions_to_check.add(
ParsedCustomFunction(
name=lambda_func.value, num_input_args=lambda_func.num_input_args()
)
)
for custom_function in custom_functions_to_check:
if custom_function_definitions[custom_function.name].contains( if custom_function_definitions[custom_function.name].contains(
variables=variables, custom_function_definitions=custom_function_definitions variables=variables, custom_function_definitions=custom_function_definitions
): ):

View file

@ -76,6 +76,28 @@ class TestLambdaFunction:
assert script.resolve().get("category_url_map").native == {1: 1, 2: 2, 3: 3} assert script.resolve().get("category_url_map").native == {1: 1, 2: 2, 3: 3}
def test_array_apply_custom_function(self):
output = (
Script(
{
"the_array": "{ ['a', 'B', 'c', 'D'] }",
"output": "{ %array_apply(the_array, %lower) }",
"should_lower": "{%bool(True)}",
"%custom_cap": """{
%if(
%bool(should_lower),
%lower($0),
%upper($0)
)
}""",
}
)
.resolve(update=True)
.get("output")
.native
)
assert output == ["a", "b", "c", "d"]
class TestLambdaFunctionIncompatibleNumArguments: class TestLambdaFunctionIncompatibleNumArguments:
@pytest.mark.parametrize( @pytest.mark.parametrize(