From 07541c4a56957d422a6ab3a945f1e409f733c292 Mon Sep 17 00:00:00 2001 From: MEPalma Date: Mon, 23 Dec 2024 15:03:00 +0100 Subject: [PATCH 1/2] stateless evalutation components, heap --- .../component/intrinsic/argument/argument.py | 92 +++++++++++++++ .../intrinsic/argument/function_argument.py | 15 --- .../argument/function_argument_bool.py | 10 -- .../function_argument_context_path.py | 17 --- .../argument/function_argument_float.py | 10 -- .../argument/function_argument_function.py | 18 --- .../argument/function_argument_int.py | 10 -- .../argument/function_argument_json_path.py | 18 --- .../argument/function_argument_list.py | 20 ---- .../argument/function_argument_string.py | 10 -- .../argument/function_argument_var.py | 22 ---- .../component/intrinsic/function/function.py | 9 +- .../function/statesfunction/array/array.py | 10 +- .../statesfunction/array/array_contains.py | 14 +-- .../statesfunction/array/array_get_item.py | 14 +-- .../statesfunction/array/array_length.py | 14 +-- .../statesfunction/array/array_partition.py | 14 +-- .../statesfunction/array/array_range.py | 14 +-- .../statesfunction/array/array_unique.py | 14 +-- .../encoding_decoding/base_64_decode.py | 14 +-- .../encoding_decoding/base_64_encode.py | 14 +-- .../function/statesfunction/factory.py | 42 ++++--- .../statesfunction/generic/string_format.py | 41 +++---- .../hash_calculations/hash_func.py | 14 +-- .../json_manipulation/json_merge.py | 14 +-- .../json_manipulation/json_to_string.py | 14 +-- .../json_manipulation/string_to_json.py | 14 +-- .../math_operations/math_add.py | 14 +-- .../math_operations/math_random.py | 16 +-- .../statesfunction/states_function.py | 8 +- .../statesfunction/states_function_array.py | 12 +- .../statesfunction/states_function_format.py | 28 ++--- .../states_function_json_to_string.py | 14 +-- .../states_function_string_to_json.py | 14 +-- .../statesfunction/states_function_uuid.py | 12 +- .../string_operations/string_split.py | 14 +-- .../unique_id_generation/uuid.py | 12 +- .../asl/component/program/program.py | 9 +- .../stepfunctions/asl/eval/environment.py | 2 +- .../asl/parse/intrinsic/preprocessor.py | 105 +++++++----------- .../v2/callback/test_callback.py | 3 +- .../v2/context_object/test_context_object.py | 3 +- .../v2/error_handling/test_states_errors.py | 9 +- .../v2/scenarios/test_base_scenarios.py | 16 +-- .../v2/services/test_lambda_task.py | 13 ++- .../v2/services/test_lambda_task_service.py | 10 +- .../v2/timeouts/test_timeouts.py | 9 +- 47 files changed, 374 insertions(+), 461 deletions(-) create mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_bool.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_context_path.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_float.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_function.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_int.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_json_path.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_list.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_string.py delete mode 100644 localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_var.py diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py new file mode 100644 index 0000000000000..3fb3c5a97a9ad --- /dev/null +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py @@ -0,0 +1,92 @@ +import abc +from typing import Any, Final, Optional + +from localstack.services.stepfunctions.asl.component.common.string.string_expression import ( + StringVariableSample, +) +from localstack.services.stepfunctions.asl.component.eval_component import EvalComponent +from localstack.services.stepfunctions.asl.eval.environment import Environment +from localstack.services.stepfunctions.asl.utils.json_path import extract_json + + +class Argument(EvalComponent, abc.ABC): + @abc.abstractmethod + def _eval_argument(self, env: Environment) -> Any: ... + + def _eval_body(self, env: Environment) -> None: + argument = self._eval_argument(env=env) + env.stack.append(argument) + + +class ArgumentLiteral(Argument): + definition_value: Final[Optional[Any]] + + def __init__(self, definition_value: Optional[Any]): + self.definition_value = definition_value + + def _eval_argument(self, env: Environment) -> Any: + return self.definition_value + + +class ArgumentJsonPath(Argument): + json_path: Final[str] + + def __init__(self, json_path: str): + self.json_path = json_path + + def _eval_argument(self, env: Environment) -> Any: + inp = env.stack[-1] + value = extract_json(self.json_path, inp) + return value + + +class ArgumentContextPath(ArgumentJsonPath): + def __init__(self, context_path: str): + json_path = context_path[1:] + super().__init__(json_path=json_path) + + def _eval_argument(self, env: Environment) -> Any: + value = extract_json(self.json_path, env.states.context_object.context_object_data) + return value + + +class ArgumentFunction(Argument): + function: Final[EvalComponent] + + def __init__(self, function: EvalComponent): + self.function = function + + def _eval_argument(self, env: Environment) -> Any: + self.function.eval(env=env) + output_value = env.stack.pop() + return output_value + + +class ArgumentVar(Argument): + string_variable_sample: Final[StringVariableSample] + + def __init__(self, string_variable_sample: StringVariableSample): + super().__init__() + self.string_variable_sample = string_variable_sample + + def _eval_argument(self, env: Environment) -> Any: + self.string_variable_sample.eval(env=env) + value = env.stack.pop() + return value + + +class ArgumentList(Argument): + arguments: Final[list[Argument]] + size: Final[int] + + def __init__(self, arguments: list[Argument]): + self.arguments = arguments + self.size = len(arguments) + + def _eval_argument(self, env: Environment) -> Any: + values = list() + for argument in self.arguments: + argument.eval(env=env) + argument_value = env.stack.pop() + values.append(argument_value) + return values diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument.py deleted file mode 100644 index 6eea8ea1f9191..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument.py +++ /dev/null @@ -1,15 +0,0 @@ -import abc -from typing import Any, Optional - -from localstack.services.stepfunctions.asl.component.eval_component import EvalComponent -from localstack.services.stepfunctions.asl.eval.environment import Environment - - -class FunctionArgument(EvalComponent, abc.ABC): - _value: Optional[Any] - - def __init__(self, value: Any = None): - self._value = value - - def _eval_body(self, env: Environment) -> None: - env.stack.append(self._value) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_bool.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_bool.py deleted file mode 100644 index 2254512f8992b..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_bool.py +++ /dev/null @@ -1,10 +0,0 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) - - -class FunctionArgumentBool(FunctionArgument): - _value: bool - - def __init__(self, boolean: bool): - super().__init__(value=boolean) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_context_path.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_context_path.py deleted file mode 100644 index 019c7f9cda259..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_context_path.py +++ /dev/null @@ -1,17 +0,0 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) -from localstack.services.stepfunctions.asl.eval.environment import Environment -from localstack.services.stepfunctions.asl.utils.json_path import extract_json - - -class FunctionArgumentContextPath(FunctionArgument): - _value: str - - def __init__(self, json_path: str): - super().__init__() - self._json_path: str = json_path - - def _eval_body(self, env: Environment) -> None: - self._value = extract_json(self._json_path, env.states.context_object.context_object_data) - super()._eval_body(env=env) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_float.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_float.py deleted file mode 100644 index c8e9d6276c95b..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_float.py +++ /dev/null @@ -1,10 +0,0 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) - - -class FunctionArgumentFloat(FunctionArgument): - _value: float - - def __init__(self, number: float): - super().__init__(value=number) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_function.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_function.py deleted file mode 100644 index 5367801d25163..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_function.py +++ /dev/null @@ -1,18 +0,0 @@ -from typing import Final - -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) -from localstack.services.stepfunctions.asl.component.intrinsic.function.function import Function -from localstack.services.stepfunctions.asl.eval.environment import Environment - - -class FunctionArgumentFunction(FunctionArgument): - def __init__(self, function: Function): - super().__init__() - self.function: Final[Function] = function - - def _eval_body(self, env: Environment) -> None: - self.function.eval(env=env) - self._value = env.stack.pop() - super()._eval_body(env=env) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_int.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_int.py deleted file mode 100644 index 075275e6f2103..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_int.py +++ /dev/null @@ -1,10 +0,0 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) - - -class FunctionArgumentInt(FunctionArgument): - _value: int - - def __init__(self, integer: int): - super().__init__(value=integer) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_json_path.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_json_path.py deleted file mode 100644 index 519a7d1448453..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_json_path.py +++ /dev/null @@ -1,18 +0,0 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) -from localstack.services.stepfunctions.asl.eval.environment import Environment -from localstack.services.stepfunctions.asl.utils.json_path import extract_json - - -class FunctionArgumentJsonPath(FunctionArgument): - _value: str - - def __init__(self, json_path: str): - super().__init__() - self._json_path: str = json_path - - def _eval_body(self, env: Environment) -> None: - inp = env.stack[-1] - self._value = extract_json(self._json_path, inp) - super()._eval_body(env=env) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_list.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_list.py deleted file mode 100644 index 4f01516f49454..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_list.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import Final - -from localstack.services.stepfunctions.asl.component.eval_component import EvalComponent -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) -from localstack.services.stepfunctions.asl.eval.environment import Environment - - -class FunctionArgumentList(EvalComponent): - def __init__(self, arg_list: list[FunctionArgument]): - self.arg_list: Final[list[FunctionArgument]] = arg_list - self.size: Final[int] = len(arg_list) - - def _eval_body(self, env: Environment) -> None: - values = list() - for arg in self.arg_list: - arg.eval(env=env) - values.append(env.stack.pop()) - env.stack.append(values) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_string.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_string.py deleted file mode 100644 index f2ac2443a3214..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_string.py +++ /dev/null @@ -1,10 +0,0 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) - - -class FunctionArgumentString(FunctionArgument): - _value: str - - def __init__(self, string: str): - super().__init__(value=string) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_var.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_var.py deleted file mode 100644 index 2f353e3f45131..0000000000000 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/function_argument_var.py +++ /dev/null @@ -1,22 +0,0 @@ -from typing import Final - -from localstack.services.stepfunctions.asl.component.common.string.string_expression import ( - StringVariableSample, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) -from localstack.services.stepfunctions.asl.eval.environment import Environment - - -class FunctionArgumentVar(FunctionArgument): - string_variable_sample: Final[StringVariableSample] - - def __init__(self, string_variable_sample: StringVariableSample): - super().__init__() - self.string_variable_sample = string_variable_sample - - def _eval_body(self, env: Environment) -> None: - self.string_variable_sample.eval(env=env) - self._value = env.stack.pop() - super()._eval_body(env=env) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/function.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/function.py index 09ad2d2db50de..dd41bdeab2028 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/function.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/function.py @@ -2,9 +2,7 @@ from typing import Final from localstack.services.stepfunctions.asl.component.eval_component import EvalComponent -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, -) +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ArgumentList from localstack.services.stepfunctions.asl.component.intrinsic.functionname.function_name import ( FunctionName, ) @@ -12,7 +10,8 @@ class Function(EvalComponent, abc.ABC): name: FunctionName + argument_list: Final[ArgumentList] - def __init__(self, name: FunctionName, arg_list: FunctionArgumentList): + def __init__(self, name: FunctionName, argument_list: ArgumentList): self.name = name - self.arg_list: Final[FunctionArgumentList] = arg_list + self.argument_list = argument_list diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array.py index ff3010e4a0bdd..1b10fa1e97735 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array.py @@ -1,7 +1,7 @@ from typing import Any -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -16,13 +16,13 @@ class Array(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.Array), - arg_list=arg_list, + argument_list=argument_list, ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) values: list[Any] = env.stack.pop() env.stack.append(values) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_contains.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_contains.py index fa56dcbb00ff8..340fa5ec6d2a9 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_contains.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_contains.py @@ -1,5 +1,5 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -28,18 +28,18 @@ class ArrayContains(StatesFunction): # # Returns: # true - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.ArrayContains), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 2: + if argument_list.size != 2: raise ValueError( - f"Expected 2 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 2 arguments for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() array = args[0] diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_get_item.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_get_item.py index 6951d58cd4ac4..fc9448d28d5a5 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_get_item.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_get_item.py @@ -1,5 +1,5 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -28,18 +28,18 @@ class ArrayGetItem(StatesFunction): # # Returns # 6 - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.ArrayGetItem), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 2: + if argument_list.size != 2: raise ValueError( - f"Expected 2 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 2 arguments for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() index = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_length.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_length.py index 9e1833a3163f7..f1050fab9aaf2 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_length.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_length.py @@ -1,5 +1,5 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -27,18 +27,18 @@ class ArrayLength(StatesFunction): # # Returns # 9 - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.ArrayLength), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() array = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_partition.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_partition.py index db77b4fbe0bfb..a12b2780c0faf 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_partition.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_partition.py @@ -1,5 +1,5 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -28,18 +28,18 @@ class ArrayPartition(StatesFunction): # Returns # [ [1,2,3,4], [5,6,7,8], [9]] - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.ArrayPartition), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 2: + if argument_list.size != 2: raise ValueError( - f"Expected 2 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 2 arguments for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() chunk_size = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_range.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_range.py index 3f0f854375be7..5528d62b57159 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_range.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_range.py @@ -1,5 +1,5 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -22,18 +22,18 @@ class ArrayRange(StatesFunction): # # Returns # [1,3,5,7,9] - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.ArrayRange), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 3: + if argument_list.size != 3: raise ValueError( - f"Expected 3 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 3 arguments for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) range_vals = env.stack.pop() for range_val in range_vals: diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_unique.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_unique.py index 6ab0c61dd5a97..93833f686ba41 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_unique.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/array/array_unique.py @@ -1,7 +1,7 @@ from collections import OrderedDict -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -29,18 +29,18 @@ class ArrayUnique(StatesFunction): # # Returns # [1,2,3,4] - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.ArrayUnique), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() array = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_decode.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_decode.py index 746ffd0fd6d21..8a4ebe8d94835 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_decode.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_decode.py @@ -1,8 +1,8 @@ import base64 from typing import Final -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -33,18 +33,18 @@ class Base64Decode(StatesFunction): MAX_INPUT_CHAR_LEN: Final[int] = 10_000 - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.Base64Decode), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() base64_string: str = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_encode.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_encode.py index 460dea8c5083e..33a72f845c0b1 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_encode.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/encoding_decoding/base_64_encode.py @@ -1,8 +1,8 @@ import base64 from typing import Final -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -33,18 +33,18 @@ class Base64Encode(StatesFunction): MAX_INPUT_CHAR_LEN: Final[int] = 10_000 - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.Base64Encode), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() string: str = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/factory.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/factory.py index bf25311b9376c..bbfb779802782 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/factory.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/factory.py @@ -1,6 +1,4 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, -) +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ArgumentList from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.array import ( array, array_contains, @@ -49,59 +47,59 @@ # TODO: could use reflection on StatesFunctionNameType values. class StatesFunctionFactory: @staticmethod - def from_name(func_name: StatesFunctionName, arg_list: FunctionArgumentList) -> StatesFunction: + def from_name(func_name: StatesFunctionName, argument_list: ArgumentList) -> StatesFunction: match func_name.function_type: # Array. case StatesFunctionNameType.Array: - return array.Array(arg_list=arg_list) + return array.Array(argument_list=argument_list) case StatesFunctionNameType.ArrayPartition: - return array_partition.ArrayPartition(arg_list=arg_list) + return array_partition.ArrayPartition(argument_list=argument_list) case StatesFunctionNameType.ArrayContains: - return array_contains.ArrayContains(arg_list=arg_list) + return array_contains.ArrayContains(argument_list=argument_list) case StatesFunctionNameType.ArrayRange: - return array_range.ArrayRange(arg_list=arg_list) + return array_range.ArrayRange(argument_list=argument_list) case StatesFunctionNameType.ArrayGetItem: - return array_get_item.ArrayGetItem(arg_list=arg_list) + return array_get_item.ArrayGetItem(argument_list=argument_list) case StatesFunctionNameType.ArrayLength: - return array_length.ArrayLength(arg_list=arg_list) + return array_length.ArrayLength(argument_list=argument_list) case StatesFunctionNameType.ArrayUnique: - return array_unique.ArrayUnique(arg_list=arg_list) + return array_unique.ArrayUnique(argument_list=argument_list) # JSON Manipulation case StatesFunctionNameType.JsonToString: - return json_to_string.JsonToString(arg_list=arg_list) + return json_to_string.JsonToString(argument_list=argument_list) case StatesFunctionNameType.StringToJson: - return string_to_json.StringToJson(arg_list=arg_list) + return string_to_json.StringToJson(argument_list=argument_list) case StatesFunctionNameType.JsonMerge: - return json_merge.JsonMerge(arg_list=arg_list) + return json_merge.JsonMerge(argument_list=argument_list) # Unique Id Generation. case StatesFunctionNameType.UUID: - return uuid.UUID(arg_list=arg_list) + return uuid.UUID(argument_list=argument_list) # String Operations. case StatesFunctionNameType.StringSplit: - return string_split.StringSplit(arg_list=arg_list) + return string_split.StringSplit(argument_list=argument_list) # Hash Calculations. case StatesFunctionNameType.Hash: - return hash_func.HashFunc(arg_list=arg_list) + return hash_func.HashFunc(argument_list=argument_list) # Encoding and Decoding. case StatesFunctionNameType.Base64Encode: - return base_64_encode.Base64Encode(arg_list=arg_list) + return base_64_encode.Base64Encode(argument_list=argument_list) case StatesFunctionNameType.Base64Decode: - return base_64_decode.Base64Decode(arg_list=arg_list) + return base_64_decode.Base64Decode(argument_list=argument_list) # Math Operations. case StatesFunctionNameType.MathRandom: - return math_random.MathRandom(arg_list=arg_list) + return math_random.MathRandom(argument_list=argument_list) case StatesFunctionNameType.MathAdd: - return math_add.MathAdd(arg_list=arg_list) + return math_add.MathAdd(argument_list=argument_list) # Generic. case StatesFunctionNameType.Format: - return string_format.StringFormat(arg_list=arg_list) + return string_format.StringFormat(argument_list=argument_list) # Unsupported. case unsupported: diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/generic/string_format.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/generic/string_format.py index 7cd763a8f4ca4..86e8b50050518 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/generic/string_format.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/generic/string_format.py @@ -1,17 +1,12 @@ import json from typing import Any, Final -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_json_path import ( - FunctionArgumentJsonPath, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_string import ( - FunctionArgumentString, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_var import ( - FunctionArgumentVar, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentContextPath, + ArgumentJsonPath, + ArgumentList, + ArgumentLiteral, + ArgumentVar, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -46,26 +41,32 @@ class StringFormat(StatesFunction): # Hello, my name is Arnav. _DELIMITER: Final[str] = "{}" - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.Format), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size == 0: + if argument_list.size == 0: + raise ValueError( + f"Expected at least 1 argument for function type '{type(self)}', but got: '{argument_list}'." + ) + first_argument = argument_list.arguments[0] + if isinstance(first_argument, ArgumentLiteral) and not isinstance( + first_argument.definition_value, str + ): raise ValueError( - f"Expected at least 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected the first argument for function type '{type(self)}' to be a string, but got: '{first_argument.definition_value}'." ) - if not isinstance( - arg_list.arg_list[0], - (FunctionArgumentString, FunctionArgumentVar, FunctionArgumentJsonPath), + elif not isinstance( + first_argument, (ArgumentLiteral, ArgumentVar, ArgumentJsonPath, ArgumentContextPath) ): raise ValueError( - f"Expected the first argument for function type '{type(self)}' to be a string, but got: '{arg_list.arg_list[0]}'." + f"Expected the first argument for function type '{type(self)}' to be a string, but got: '{first_argument}'." ) def _eval_body(self, env: Environment) -> None: # TODO: investigate behaviour for incorrect number of arguments in string format. - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() string_format: str = args[0] diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/hash_calculations/hash_func.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/hash_calculations/hash_func.py index 364a86ec4ec95..135f73826f86b 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/hash_calculations/hash_func.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/hash_calculations/hash_func.py @@ -1,8 +1,8 @@ import hashlib from typing import Final -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.hash_calculations.hash_algorithm import ( HashAlgorithm, @@ -22,14 +22,14 @@ class HashFunc(StatesFunction): MAX_INPUT_CHAR_LEN: Final[int] = 10_000 - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.Hash), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 2: + if argument_list.size != 2: raise ValueError( - f"Expected 2 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 2 arguments for function type '{type(self)}', but got: '{argument_list}'." ) @staticmethod @@ -51,7 +51,7 @@ def _hash_inp_with_alg(inp: str, alg: HashAlgorithm) -> str: return hash_value def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() algorithm = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_merge.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_merge.py index 6de0b2f9faea8..a6e9221d26c81 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_merge.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_merge.py @@ -1,8 +1,8 @@ import copy from typing import Any -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -38,14 +38,14 @@ class JsonMerge(StatesFunction): # } # } - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.JsonMerge), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 3: + if argument_list.size != 3: raise ValueError( - f"Expected 3 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 3 arguments for function type '{type(self)}', but got: '{argument_list}'." ) @staticmethod @@ -67,7 +67,7 @@ def _validate_merge_argument(argument: Any, num: int) -> None: raise TypeError(f"Expected a JSON object the argument {num}, but got: '{argument}'.") def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() is_deep_merge = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_to_string.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_to_string.py index bc1c46851f8bf..9dfff92d8c449 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_to_string.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/json_to_string.py @@ -1,7 +1,7 @@ import json -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -16,18 +16,18 @@ class JsonToString(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.JsonToString), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() json_obj: json = args.pop() json_string: str = json.dumps(json_obj, separators=(",", ":")) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/string_to_json.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/string_to_json.py index 10bc5c4a31cdc..cc42874cf2baa 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/string_to_json.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/json_manipulation/string_to_json.py @@ -1,7 +1,7 @@ import json -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -16,18 +16,18 @@ class StringToJson(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.StringToJson), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() string_json: str = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_add.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_add.py index a30cfee821226..c4124f1195159 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_add.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_add.py @@ -1,8 +1,8 @@ import decimal from typing import Any -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -44,14 +44,14 @@ class MathAdd(StatesFunction): # Returns # {"value1": 110 } - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.MathAdd), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 2: + if argument_list.size != 2: raise ValueError( - f"Expected 2 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 2 arguments for function type '{type(self)}', but got: '{argument_list}'." ) @staticmethod @@ -68,7 +68,7 @@ def _validate_integer_value(value: Any) -> int: return value def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() a = self._validate_integer_value(args[0]) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_random.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_random.py index 2d3a819c3e6fe..b50d1dcb4368d 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_random.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_random.py @@ -1,8 +1,8 @@ import random from typing import Any -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -32,14 +32,14 @@ class MathRandom(StatesFunction): # Returns # {"random": 456 } - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.MathRandom), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size < 2 or arg_list.size > 3: + if argument_list.size < 2 or argument_list.size > 3: raise ValueError( - f"Expected 2-3 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 2-3 arguments for function type '{type(self)}', but got: '{argument_list}'." ) @staticmethod @@ -51,11 +51,11 @@ def _validate_integer_value(value: Any, argument_name: str) -> int: return int(value) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() seed = None - if self.arg_list.size == 3: + if self.argument_list.size == 3: seed = args.pop() self._validate_integer_value(seed, "seed") diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function.py index f21b5f5ca7d3f..dfb4b6e420560 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function.py @@ -1,7 +1,7 @@ import abc -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.function import Function from localstack.services.stepfunctions.asl.component.intrinsic.functionname.states_function_name import ( @@ -12,5 +12,5 @@ class StatesFunction(Function, abc.ABC): name: StatesFunctionName - def __init__(self, states_name: StatesFunctionName, arg_list: FunctionArgumentList): - super().__init__(name=states_name, arg_list=arg_list) + def __init__(self, states_name: StatesFunctionName, argument_list: ArgumentList): + super().__init__(name=states_name, argument_list=argument_list) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_array.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_array.py index f5f0c78e31b3b..5cce091f0fd85 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_array.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_array.py @@ -1,7 +1,7 @@ from typing import Any -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -16,16 +16,16 @@ class StatesFunctionArray(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.Array), - arg_list=arg_list, + argument_list=argument_list, ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) values: list[Any] = list() - for _ in range(self.arg_list.size): + for _ in range(self.argument_list.size): values.append(env.stack.pop()) values.reverse() env.stack.append(values) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_format.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_format.py index 5a44db937028f..8b71a07fbd122 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_format.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_format.py @@ -1,10 +1,8 @@ from typing import Any, Final -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_string import ( - FunctionArgumentString, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, + ArgumentLiteral, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -21,26 +19,30 @@ class StatesFunctionFormat(StatesFunction): _DELIMITER: Final[str] = "{}" - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.Format), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size > 0: + if argument_list.size == 0: raise ValueError( - f"Expected at least 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected at least 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) - if not isinstance(arg_list.arg_list[0], FunctionArgumentString): + first_argument = argument_list.arguments[0] + if not ( + isinstance(first_argument, ArgumentLiteral) + and isinstance(first_argument.definition_value, str) + ): raise ValueError( - f"Expected the first argument for function type '{type(self)}' to be a string, but got: '{arg_list.arg_list[0]}'." + f"Expected the first argument for function type '{type(self)}' to be a string, but got: '{first_argument}'." ) def _eval_body(self, env: Environment) -> None: # TODO: investigate behaviour for incorrect number of arguments in string format. - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) values: list[Any] = list() - for _ in range(self.arg_list.size): + for _ in range(self.argument_list.size): values.append(env.stack.pop()) string_format: str = values.pop() values.reverse() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_json_to_string.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_json_to_string.py index 351b0f197883e..f2a29724dad80 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_json_to_string.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_json_to_string.py @@ -1,7 +1,7 @@ import json -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -16,18 +16,18 @@ class StatesFunctionJsonToString(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.JsonToString), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) json_obj: json = env.stack.pop() json_string: str = json.dumps(json_obj) env.stack.append(json_string) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_string_to_json.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_string_to_json.py index af883fe849d86..1dde28d4257e1 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_string_to_json.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_string_to_json.py @@ -1,7 +1,7 @@ import json -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -16,18 +16,18 @@ class StatesFunctionStringToJson(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.StringToJson), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 1: + if argument_list.size != 1: raise ValueError( - f"Expected 1 argument for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 1 argument for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) string_json: str = env.stack.pop() json_obj: json = json.loads(string_json) env.stack.append(json_obj) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_uuid.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_uuid.py index 63f95e94ba0d3..34b23541e0b0a 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_uuid.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/states_function_uuid.py @@ -1,5 +1,5 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -15,14 +15,14 @@ class StatesFunctionUUID(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.UUID), - arg_list=arg_list, + argument_list=argument_list, ) - if len(arg_list.arg_list) != 0: + if argument_list.size != 0: raise ValueError( - f"Expected no arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected no arguments for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/string_operations/string_split.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/string_operations/string_split.py index c4a699593bca3..a1187e9aa4465 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/string_operations/string_split.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/string_operations/string_split.py @@ -1,7 +1,7 @@ import re -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -38,18 +38,18 @@ class StringSplit(StatesFunction): # "test", # "string" # ]} - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.StringSplit), - arg_list=arg_list, + argument_list=argument_list, ) - if arg_list.size != 2: + if argument_list.size != 2: raise ValueError( - f"Expected 2 arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected 2 arguments for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: - self.arg_list.eval(env=env) + self.argument_list.eval(env=env) args = env.stack.pop() del_chars = args.pop() diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/unique_id_generation/uuid.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/unique_id_generation/uuid.py index 3501c8da283d7..1a0d6a75f7b09 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/unique_id_generation/uuid.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/unique_id_generation/uuid.py @@ -1,5 +1,5 @@ -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + ArgumentList, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.states_function import ( StatesFunction, @@ -15,14 +15,14 @@ class UUID(StatesFunction): - def __init__(self, arg_list: FunctionArgumentList): + def __init__(self, argument_list: ArgumentList): super().__init__( states_name=StatesFunctionName(function_type=StatesFunctionNameType.UUID), - arg_list=arg_list, + argument_list=argument_list, ) - if len(arg_list.arg_list) != 0: + if argument_list.size != 0: raise ValueError( - f"Expected no arguments for function type '{type(self)}', but got: '{arg_list}'." + f"Expected no arguments for function type '{type(self)}', but got: '{argument_list}'." ) def _eval_body(self, env: Environment) -> None: diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/program/program.py b/localstack-core/localstack/services/stepfunctions/asl/component/program/program.py index a68fe9e78e239..e86a5cd076620 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/program/program.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/program/program.py @@ -87,18 +87,11 @@ def eval(self, env: Environment) -> None: def _eval_body(self, env: Environment) -> None: try: while env.is_running(): - # Store the heap values at this depth for garbage collection. - heap_values = set(env.heap.keys()) - next_state: CommonStateField = self._get_state(env.next_state_name) next_state.eval(env) - # Garbage collect hanging values added by this last state. env.stack.clear() - clear_heap_values = set(env.heap.keys()) - heap_values - for heap_value in clear_heap_values: - env.heap.pop(heap_value, None) - + env.heap.clear() except FailureEventException as ex: env.set_error(error=ex.get_execution_failed_event_details()) except Exception as ex: diff --git a/localstack-core/localstack/services/stepfunctions/asl/eval/environment.py b/localstack-core/localstack/services/stepfunctions/asl/eval/environment.py index 29cd95559cd73..ffcecca7240e7 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/eval/environment.py +++ b/localstack-core/localstack/services/stepfunctions/asl/eval/environment.py @@ -142,7 +142,7 @@ def as_inner_frame_of( ) frame.callback_pool_manager = env.callback_pool_manager frame.map_run_record_pool_manager = env.map_run_record_pool_manager - frame.heap = env.heap + frame.heap = dict() frame._program_state = copy.deepcopy(env._program_state) return frame diff --git a/localstack-core/localstack/services/stepfunctions/asl/parse/intrinsic/preprocessor.py b/localstack-core/localstack/services/stepfunctions/asl/parse/intrinsic/preprocessor.py index 9ebe45fd1c1b7..dca48b0b65d90 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/parse/intrinsic/preprocessor.py +++ b/localstack-core/localstack/services/stepfunctions/asl/parse/intrinsic/preprocessor.py @@ -18,35 +18,14 @@ StringVariableSample, ) from localstack.services.stepfunctions.asl.component.component import Component -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument import ( - FunctionArgument, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_bool import ( - FunctionArgumentBool, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_context_path import ( - FunctionArgumentContextPath, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_float import ( - FunctionArgumentFloat, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_function import ( - FunctionArgumentFunction, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_int import ( - FunctionArgumentInt, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_json_path import ( - FunctionArgumentJsonPath, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import ( - FunctionArgumentList, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_string import ( - FunctionArgumentString, -) -from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_var import ( - FunctionArgumentVar, +from localstack.services.stepfunctions.asl.component.intrinsic.argument.argument import ( + Argument, + ArgumentContextPath, + ArgumentFunction, + ArgumentJsonPath, + ArgumentList, + ArgumentLiteral, + ArgumentVar, ) from localstack.services.stepfunctions.asl.component.intrinsic.function.function import Function from localstack.services.stepfunctions.asl.component.intrinsic.function.statesfunction.factory import ( @@ -83,64 +62,58 @@ def _text_of_str(parse_tree: ParseTree) -> str: inner_str = re.sub(r"\\(.)", Preprocessor._replace_escaped_characters, inner_str) return inner_str - def visitFunc_arg_int(self, ctx: ASLIntrinsicParser.Func_arg_intContext) -> FunctionArgumentInt: + def visitFunc_arg_int(self, ctx: ASLIntrinsicParser.Func_arg_intContext) -> ArgumentLiteral: integer = int(ctx.INT().getText()) - return FunctionArgumentInt(integer=integer) + return ArgumentLiteral(definition_value=integer) - def visitFunc_arg_float( - self, ctx: ASLIntrinsicParser.Func_arg_floatContext - ) -> FunctionArgumentFloat: + def visitFunc_arg_float(self, ctx: ASLIntrinsicParser.Func_arg_floatContext) -> ArgumentLiteral: number = float(ctx.INT().getText()) - return FunctionArgumentFloat(number=number) + return ArgumentLiteral(definition_value=number) def visitFunc_arg_string( self, ctx: ASLIntrinsicParser.Func_arg_stringContext - ) -> FunctionArgumentString: + ) -> ArgumentLiteral: text: str = self._text_of_str(ctx.STRING()) - return FunctionArgumentString(string=text) + return ArgumentLiteral(definition_value=text) + + def visitFunc_arg_bool(self, ctx: ASLIntrinsicParser.Func_arg_boolContext) -> ArgumentLiteral: + bool_term: TerminalNodeImpl = ctx.children[0] + bool_term_rule: int = bool_term.getSymbol().type + bool_val: bool = bool_term_rule == ASLIntrinsicLexer.TRUE + return ArgumentLiteral(definition_value=bool_val) + + def visitFunc_arg_list(self, ctx: ASLIntrinsicParser.Func_arg_listContext) -> ArgumentList: + arguments: list[Argument] = list() + for child in ctx.children: + cmp: Optional[Component] = self.visit(child) + if isinstance(cmp, Argument): + arguments.append(cmp) + return ArgumentList(arguments=arguments) def visitFunc_arg_context_path( self, ctx: ASLIntrinsicParser.Func_arg_context_pathContext - ) -> FunctionArgumentContextPath: - json_path: str = ctx.CONTEXT_PATH_STRING().getText()[1:] - return FunctionArgumentContextPath(json_path=json_path) + ) -> ArgumentContextPath: + context_path: str = ctx.CONTEXT_PATH_STRING().getText() + return ArgumentContextPath(context_path=context_path) def visitFunc_arg_json_path( self, ctx: ASLIntrinsicParser.Func_arg_json_pathContext - ) -> FunctionArgumentJsonPath: + ) -> ArgumentJsonPath: json_path: str = ctx.JSON_PATH_STRING().getText() - return FunctionArgumentJsonPath(json_path=json_path) + return ArgumentJsonPath(json_path=json_path) - def visitFunc_arg_var(self, ctx: ASLIntrinsicParser.Func_arg_varContext) -> FunctionArgumentVar: + def visitFunc_arg_var(self, ctx: ASLIntrinsicParser.Func_arg_varContext) -> ArgumentVar: expression: str = ctx.STRING_VARIABLE().getText() string_variable_sample = StringVariableSample( query_language_mode=QueryLanguageMode.JSONPath, expression=expression ) - return FunctionArgumentVar(string_variable_sample=string_variable_sample) + return ArgumentVar(string_variable_sample=string_variable_sample) def visitFunc_arg_func_decl( self, ctx: ASLIntrinsicParser.Func_arg_func_declContext - ) -> FunctionArgumentFunction: + ) -> ArgumentFunction: function: Function = self.visit(ctx.states_func_decl()) - return FunctionArgumentFunction(function=function) - - def visitFunc_arg_bool( - self, ctx: ASLIntrinsicParser.Func_arg_boolContext - ) -> FunctionArgumentBool: - bool_term: TerminalNodeImpl = ctx.children[0] - bool_term_rule: int = bool_term.getSymbol().type - bool_val: bool = bool_term_rule == ASLIntrinsicLexer.TRUE - return FunctionArgumentBool(boolean=bool_val) - - def visitFunc_arg_list( - self, ctx: ASLIntrinsicParser.Func_arg_listContext - ) -> FunctionArgumentList: - arg_list: list[FunctionArgument] = list() - for child in ctx.children: - cmp: Optional[Component] = self.visit(child) - if isinstance(cmp, FunctionArgument): - arg_list.append(cmp) - return FunctionArgumentList(arg_list=arg_list) + return ArgumentFunction(function=function) def visitState_fun_name( self, ctx: ASLIntrinsicParser.State_fun_nameContext @@ -153,9 +126,9 @@ def visitStates_func_decl( self, ctx: ASLIntrinsicParser.States_func_declContext ) -> StatesFunction: func_name: StatesFunctionName = self.visit(ctx.state_fun_name()) - arg_list: FunctionArgumentList = self.visit(ctx.func_arg_list()) + argument_list: ArgumentList = self.visit(ctx.func_arg_list()) func: StatesFunction = StatesFunctionFactory.from_name( - func_name=func_name, arg_list=arg_list + func_name=func_name, argument_list=argument_list ) return func diff --git a/tests/aws/services/stepfunctions/v2/callback/test_callback.py b/tests/aws/services/stepfunctions/v2/callback/test_callback.py index fbe49f4f902ca..7a3d7000837bb 100644 --- a/tests/aws/services/stepfunctions/v2/callback/test_callback.py +++ b/tests/aws/services/stepfunctions/v2/callback/test_callback.py @@ -4,6 +4,7 @@ import pytest from localstack_snapshot.snapshots.transformer import JsonpathTransformer, RegexTransformer +from localstack.aws.api.lambda_ import Runtime from localstack.services.stepfunctions.asl.eval.count_down_latch import CountDownLatch from localstack.testing.aws.util import is_aws_cloud from localstack.testing.pytest import markers @@ -467,7 +468,7 @@ def test_start_execution_sync_delegate_timeout( lambda_creation_response = create_lambda_function( func_name=function_name, handler_file=TT.LAMBDA_WAIT_60_SECONDS, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) lambda_arn = lambda_creation_response["CreateFunctionResponse"]["FunctionArn"] diff --git a/tests/aws/services/stepfunctions/v2/context_object/test_context_object.py b/tests/aws/services/stepfunctions/v2/context_object/test_context_object.py index 9d1be7f2ae6a0..e8a9b1fbb1ab9 100644 --- a/tests/aws/services/stepfunctions/v2/context_object/test_context_object.py +++ b/tests/aws/services/stepfunctions/v2/context_object/test_context_object.py @@ -3,6 +3,7 @@ import pytest from localstack_snapshot.snapshots.transformer import RegexTransformer +from localstack.aws.api.lambda_ import Runtime from localstack.testing.pytest import markers from localstack.testing.pytest.stepfunctions.utils import ( create_and_record_execution, @@ -92,7 +93,7 @@ def test_result_selector( create_lambda_function( func_name=function_name, handler_file=ST.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) diff --git a/tests/aws/services/stepfunctions/v2/error_handling/test_states_errors.py b/tests/aws/services/stepfunctions/v2/error_handling/test_states_errors.py index cdbdab6b50938..125016f96ee55 100644 --- a/tests/aws/services/stepfunctions/v2/error_handling/test_states_errors.py +++ b/tests/aws/services/stepfunctions/v2/error_handling/test_states_errors.py @@ -2,6 +2,7 @@ from localstack_snapshot.snapshots.transformer import RegexTransformer +from localstack.aws.api.lambda_ import Runtime from localstack.testing.pytest import markers from localstack.testing.pytest.stepfunctions.utils import ( create_and_record_execution, @@ -32,7 +33,7 @@ def test_service_task_lambada_data_limit_exceeded_on_large_utf8_response( create_lambda_function( func_name=function_name, handler_file=EHT.LAMBDA_FUNC_LARGE_OUTPUT_STRING, - runtime="python3.12", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) @@ -69,7 +70,7 @@ def test_service_task_lambada_catch_state_all_data_limit_exceeded_on_large_utf8_ create_lambda_function( func_name=function_name, handler_file=EHT.LAMBDA_FUNC_LARGE_OUTPUT_STRING, - runtime="python3.12", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) @@ -108,7 +109,7 @@ def test_task_lambda_data_limit_exceeded_on_large_utf8_response( create_lambda_response = create_lambda_function( func_name=function_name, handler_file=EHT.LAMBDA_FUNC_LARGE_OUTPUT_STRING, - runtime="python3.12", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) function_arn = create_lambda_response["CreateFunctionResponse"]["FunctionArn"] @@ -149,7 +150,7 @@ def test_task_lambda_catch_state_all_data_limit_exceeded_on_large_utf8_response( create_lambda_response = create_lambda_function( func_name=function_name, handler_file=EHT.LAMBDA_FUNC_LARGE_OUTPUT_STRING, - runtime="python3.12", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) function_arn = create_lambda_response["CreateFunctionResponse"]["FunctionArn"] diff --git a/tests/aws/services/stepfunctions/v2/scenarios/test_base_scenarios.py b/tests/aws/services/stepfunctions/v2/scenarios/test_base_scenarios.py index c5f3a66d4fe93..d6c565e04726f 100644 --- a/tests/aws/services/stepfunctions/v2/scenarios/test_base_scenarios.py +++ b/tests/aws/services/stepfunctions/v2/scenarios/test_base_scenarios.py @@ -41,7 +41,7 @@ def test_catch_states_runtime( create_res = create_lambda_function( func_name=function_name, handler_file=SerT.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) function_arn = create_res["CreateFunctionResponse"]["FunctionArn"] @@ -73,7 +73,7 @@ def test_catch_empty( create_res = create_lambda_function( func_name=function_name, handler_file=SerT.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) function_arn = create_res["CreateFunctionResponse"]["FunctionArn"] @@ -2133,7 +2133,7 @@ def test_lambda_empty_retry( create_res = create_lambda_function( func_name=function_name, handler_file=EHT.LAMBDA_FUNC_RAISE_EXCEPTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) function_arn = create_res["CreateFunctionResponse"]["FunctionArn"] @@ -2166,7 +2166,7 @@ def test_lambda_invoke_with_retry_base( create_1_res = create_lambda_function( func_name=function_1_name, handler_file=EHT.LAMBDA_FUNC_RAISE_EXCEPTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_1_name, "")) @@ -2211,7 +2211,7 @@ def test_lambda_invoke_with_retry_extended_input( create_1_res = create_lambda_function( func_name=function_1_name, handler_file=EHT.LAMBDA_FUNC_RAISE_EXCEPTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_1_name, "")) @@ -2256,7 +2256,7 @@ def test_lambda_service_invoke_with_retry_extended_input( create_lambda_function( func_name=function_1_name, handler_file=EHT.LAMBDA_FUNC_RAISE_EXCEPTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_1_name, "")) @@ -2288,7 +2288,7 @@ def test_retry_interval_features( create_res = create_lambda_function( func_name=function_name, handler_file=EHT.LAMBDA_FUNC_RAISE_EXCEPTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) function_arn = create_res["CreateFunctionResponse"]["FunctionArn"] @@ -2320,7 +2320,7 @@ def test_retry_interval_features_jitter_none( create_res = create_lambda_function( func_name=function_name, handler_file=EHT.LAMBDA_FUNC_RAISE_EXCEPTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) function_arn = create_res["CreateFunctionResponse"]["FunctionArn"] diff --git a/tests/aws/services/stepfunctions/v2/services/test_lambda_task.py b/tests/aws/services/stepfunctions/v2/services/test_lambda_task.py index 35b5f36847af6..b52ed61556e0c 100644 --- a/tests/aws/services/stepfunctions/v2/services/test_lambda_task.py +++ b/tests/aws/services/stepfunctions/v2/services/test_lambda_task.py @@ -3,6 +3,7 @@ import pytest from localstack_snapshot.snapshots.transformer import RegexTransformer +from localstack.aws.api.lambda_ import Runtime from localstack.testing.pytest import markers from localstack.testing.pytest.stepfunctions.utils import ( create_and_record_execution, @@ -28,7 +29,7 @@ def test_invoke_bytes_payload( create_1_res = create_lambda_function( func_name=function_1_name, handler_file=ST.LAMBDA_RETURN_BYTES_STR, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_1_name, "")) @@ -61,7 +62,7 @@ def test_invoke_string_payload( create_1_res = create_lambda_function( func_name=function_1_name, handler_file=ST.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_1_name, "")) @@ -107,7 +108,7 @@ def test_invoke_json_values( create_1_res = create_lambda_function( func_name=function_1_name, handler_file=ST.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_1_name, "")) @@ -140,7 +141,7 @@ def test_invoke_pipe( create_1_res = create_lambda_function( func_name=function_1_name, handler_file=lambda_functions.ECHO_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_1_name, "")) @@ -148,7 +149,7 @@ def test_invoke_pipe( create_2_res = create_lambda_function( func_name=function_2_name, handler_file=lambda_functions.ECHO_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_2_name, "")) @@ -184,7 +185,7 @@ def test_lambda_task_filter_parameters_input( create_res = create_lambda_function( func_name=function_name, handler_file=ST.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "lambda_function_name")) function_arn = create_res["CreateFunctionResponse"]["FunctionArn"] diff --git a/tests/aws/services/stepfunctions/v2/services/test_lambda_task_service.py b/tests/aws/services/stepfunctions/v2/services/test_lambda_task_service.py index cc5441556e49f..8da727e29938e 100644 --- a/tests/aws/services/stepfunctions/v2/services/test_lambda_task_service.py +++ b/tests/aws/services/stepfunctions/v2/services/test_lambda_task_service.py @@ -3,7 +3,7 @@ import pytest from localstack_snapshot.snapshots.transformer import JsonpathTransformer, RegexTransformer -from localstack.aws.api.lambda_ import LogType +from localstack.aws.api.lambda_ import LogType, Runtime from localstack.testing.aws.util import is_aws_cloud from localstack.testing.pytest import markers from localstack.testing.pytest.stepfunctions.utils import ( @@ -36,7 +36,7 @@ def test_invoke( create_lambda_function( func_name=function_name, handler_file=ST.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) @@ -66,7 +66,7 @@ def test_invoke_bytes_payload( create_lambda_function( func_name=function_name, handler_file=ST.LAMBDA_RETURN_BYTES_STR, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) @@ -99,7 +99,7 @@ def test_invoke_unsupported_param( create_lambda_function( func_name=function_name, handler_file=ST.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) sfn_snapshot.add_transformer( @@ -147,7 +147,7 @@ def test_invoke_json_values( create_lambda_function( func_name=function_name, handler_file=ST.LAMBDA_ID_FUNCTION, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) sfn_snapshot.add_transformer( diff --git a/tests/aws/services/stepfunctions/v2/timeouts/test_timeouts.py b/tests/aws/services/stepfunctions/v2/timeouts/test_timeouts.py index c6807f01bc316..0d0c786c54436 100644 --- a/tests/aws/services/stepfunctions/v2/timeouts/test_timeouts.py +++ b/tests/aws/services/stepfunctions/v2/timeouts/test_timeouts.py @@ -3,6 +3,7 @@ import pytest from localstack_snapshot.snapshots.transformer import RegexTransformer +from localstack.aws.api.lambda_ import Runtime from localstack.testing.aws.util import is_aws_cloud from localstack.testing.pytest import markers from localstack.testing.pytest.stepfunctions.utils import ( @@ -74,7 +75,7 @@ def test_fixed_timeout_service_lambda( create_lambda_function( func_name=function_name, handler_file=TT.LAMBDA_WAIT_60_SECONDS, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) @@ -106,7 +107,7 @@ def test_fixed_timeout_service_lambda_with_path( create_lambda_function( func_name=function_name, handler_file=TT.LAMBDA_WAIT_60_SECONDS, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) @@ -140,7 +141,7 @@ def test_fixed_timeout_lambda( lambda_creation_response = create_lambda_function( func_name=function_name, handler_file=TT.LAMBDA_WAIT_60_SECONDS, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) lambda_arn = lambda_creation_response["CreateFunctionResponse"]["FunctionArn"] @@ -175,7 +176,7 @@ def test_service_lambda_map_timeout( create_lambda_function( func_name=function_name, handler_file=TT.LAMBDA_WAIT_60_SECONDS, - runtime="python3.9", + runtime=Runtime.python3_12, ) sfn_snapshot.add_transformer(RegexTransformer(function_name, "")) From 6c203a19e0f16b7d6251e51be30731b32e2bab6b Mon Sep 17 00:00:00 2001 From: MEPalma <64580864+MEPalma@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:58:54 +0100 Subject: [PATCH 2/2] pr items --- .../asl/component/intrinsic/argument/argument.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py index 3fb3c5a97a9ad..6438471c8becb 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/intrinsic/argument/argument.py @@ -10,6 +10,19 @@ class Argument(EvalComponent, abc.ABC): + """ + Represents an Intrinsic Function argument that can be evaluated and whose + result is pushed onto the stack. + + Subclasses must override `_eval_argument()` to evaluate the specific value + of the argument they represent. This abstract class manages the type and + environment handling by appending the evaluated result to the environment's + stack in `_eval_body`. + + The `_eval_body` method calls `_eval_argument()` and pushes the resulting + value to the stack. + """ + @abc.abstractmethod def _eval_argument(self, env: Environment) -> Any: ...