From e93b0b0d972e658c00f8c786314fc47f26ae64f9 Mon Sep 17 00:00:00 2001 From: Flaviu Vadan Date: Wed, 22 Mar 2023 09:57:46 -0600 Subject: [PATCH] use MISSING vs None in parameter inference (#499) Signed-off-by: Flaviu Vadan --- .github/workflows/cicd.yaml | 2 ++ src/hera/task.py | 8 ++++---- tests/test_task.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 9ac71233e..8beba4e85 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -5,12 +5,14 @@ on: branches: - main - hera/v5 + - hera/v4-n-n paths: - "src/**" pull_request: branches: - main - hera/v5 + - hera/v4-n-n paths: - "src/**" diff --git a/src/hera/task.py b/src/hera/task.py index da189eeb6..8a08390ca 100644 --- a/src/hera/task.py +++ b/src/hera/task.py @@ -34,7 +34,7 @@ from hera.memoize import Memoize from hera.metric import Metric, Metrics from hera.operator import Operator -from hera.parameter import Parameter +from hera.parameter import Parameter, MISSING from hera.port import ContainerPort from hera.resource_template import ResourceTemplate from hera.resources import Resources @@ -696,12 +696,12 @@ def _deduce_input_params_from_source(self) -> List[Parameter]: # If there are any kwargs arguments associated with the function signature, # we store these as we can set them as default values for argo arguments - source_signature: Dict[str, Optional[str]] = {} + source_signature: Dict[str, Optional[Any]] = {} for p in inspect.signature(self.source).parameters.values(): if p.default != inspect.Parameter.empty and p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD: source_signature[p.name] = p.default else: - source_signature[p.name] = None + source_signature[p.name] = MISSING # Deduce input parameters from function source. Only add those which haven't been explicitly set in inputs input_params_names = [p.name for p in self.inputs if isinstance(p, Parameter)] @@ -772,7 +772,7 @@ def _deduce_input_params_from_source(self) -> List[Parameter]: # Verify that we're utilizing 'item' if not any([p.contains_item for p in self.inputs + deduced_params]): # type: ignore raise ValueError( - "`with_param` or `with_sequence` items are utilized in inputs, nor could they be deduced" + "`with_param` or `with_sequence` items are not utilized in inputs, nor could they be deduced" ) return deduced_params diff --git a/tests/test_task.py b/tests/test_task.py index d4792f809..3c0d9af2d 100644 --- a/tests/test_task.py +++ b/tests/test_task.py @@ -832,7 +832,7 @@ def test_task_uses_sequences(self): assert t.with_sequence.format == "abc" def test_task_utilize_items(self, no_op): - error_string = "`with_param` or `with_sequence` items are utilized in inputs, nor could they be deduced" + error_string = "`with_param` or `with_sequence` items are not utilized in inputs, nor could they be deduced" with pytest.raises(ValueError) as e: Task("t", no_op, with_sequence=Sequence("abc", start=1, end=42)) assert str(e.value) == error_string