Skip to content

Commit

Permalink
Merge pull request #3286 from starhel/fix-optional-parameter-summary
Browse files Browse the repository at this point in the history
Fix execution summary for optional parameters
  • Loading branch information
dlstadther authored May 8, 2024
2 parents ed530b8 + fd7a5b1 commit 318a81d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion luigi/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def normalize(self, x):
"""
return x # default impl

def next_in_enumeration(self, _value):
def next_in_enumeration(self, value):
"""
If your Parameter type has an enumerable ordering of values. You can
choose to override this method. This method is used by the
Expand Down Expand Up @@ -389,6 +389,9 @@ def _warn_on_wrong_param_type(self, param_name, param_value):
OptionalParameterTypeWarning,
)

def next_in_enumeration(self, value):
return None


class OptionalParameter(OptionalParameterMixin, Parameter):
"""Class to parse optional parameters."""
Expand Down
2 changes: 1 addition & 1 deletion test/list_parameter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_schema(self):

# Check that invalid lists raise correct errors
invalid_list_type = ["NOT AN INT"]
invalid_list_value = [-999, 999]
invalid_list_value = [-999, 4]

with pytest.raises(ValidationError, match="'NOT AN INT' is not of type 'number'"):
a.normalize(invalid_list_type)
Expand Down
4 changes: 4 additions & 0 deletions test/optional_parameter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def run(self):
# Test parsing empty string (should be None)
self.assertIsNone(cls(**kwargs).parse(''))

# Test next_in_enumeration always returns None for summary
self.assertIsNone(TestConfig.param.next_in_enumeration(expected_value))
self.assertIsNone(TestConfig.param.next_in_enumeration(None))

# Test that warning is raised only with bad type
with mock.patch('luigi.parameter.warnings') as warnings:
TestConfig()
Expand Down

0 comments on commit 318a81d

Please sign in to comment.