Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions keep/iohandler/iohandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,11 @@ def _parse(self, tree):
pass
else:
_arg = arg.id
# if the value is empty '', we still need to pass it to the function
# also, if the value is 0 or 0.0, we need to pass it to the function
# 0 == False, so we need to check if the value is not False explicitly
if (
_arg
or _arg == ""
or (_arg == 0 or _arg == 0.0)
and _arg is not False
):
# _arg only ever stays None when none of the branches above
# produced a value (e.g. a nested keep.* call returned nothing).
# Any other parsed value - including "", 0, 0.0, False, [], {},
# and () - is a legitimate argument and must be passed through.
if _arg is not None:
_args.append(_arg)

# Parse keyword args
Expand Down
21 changes: 21 additions & 0 deletions tests/test_iohandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ def test_with_function(context_manager):
s = iohandler.render("hello keep.len({{ steps.some_list }})")
assert s == "hello 3"


@pytest.mark.parametrize(
"test_input, expected_output",
[
("res keep.join([], '-')", "res "),
("res keep.join({}, '-')", "res "),
("res keep.len([])", "res 0"),
],
)
def test_with_function_empty_container_argument(
context_manager, test_input, expected_output
):
"""
A literal [] or {} argument to a keep.* function must be passed through
as an empty list/dict, not silently dropped - see issue #6728.
"""
iohandler = IOHandler(context_manager)
s = iohandler.render(test_input)
assert s == expected_output


@pytest.mark.parametrize(
"test_input, expected_output",
[
Expand Down
Loading