Skip to content

Commit

Permalink
use MISSING vs None in parameter inference (#499)
Browse files Browse the repository at this point in the history
Signed-off-by: Flaviu Vadan <[email protected]>
  • Loading branch information
flaviuvadan authored Mar 22, 2023
1 parent 924aa04 commit e93b0b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**"

Expand Down
8 changes: 4 additions & 4 deletions src/hera/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e93b0b0

Please sign in to comment.