Skip to content

Commit e9d6d30

Browse files
committed
Handled the pickValue in the check_types function to avoid unnecessary warnings.
1 parent c4e10e3 commit e9d6d30

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

cwl_utils/parser/cwl_v1_2_utils.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def check_all_types(
210210
extra_message = (
211211
"pickValue is %s" % sink.pickValue if sink.pickValue is not None else None
212212
)
213+
sink_type = type_dict[sink.id]
213214
match sink:
214215
case cwl.WorkflowOutputParameter():
215216
sourceName = "outputSource"
@@ -231,6 +232,8 @@ def check_all_types(
231232
srcs_of_sink += [src_dict[parm_id]]
232233
if (
233234
_is_conditional_step(param_to_step, parm_id)
235+
and "null" != sink_type
236+
and "null" not in sink_type
234237
and sink.pickValue is not None
235238
):
236239
validation["warning"].append(
@@ -289,8 +292,9 @@ def check_all_types(
289292
for src in srcs_of_sink:
290293
check_result = check_types(
291294
type_dict[cast(str, src.id)],
292-
type_dict[sink.id],
295+
sink_type,
293296
linkMerge,
297+
sink.pickValue,
294298
getattr(sink, "valueFrom", None),
295299
)
296300
if check_result in ("warning", "exception"):
@@ -304,6 +308,7 @@ def check_types(
304308
srctype: Any,
305309
sinktype: Any,
306310
linkMerge: str | None,
311+
pickValue: str | None = None,
307312
valueFrom: str | None = None,
308313
) -> str:
309314
"""
@@ -313,6 +318,26 @@ def check_types(
313318
"""
314319
if valueFrom is not None:
315320
return "pass"
321+
if pickValue is not None:
322+
if isinstance(srctype, cwl.ArraySchema):
323+
match pickValue:
324+
case "all_non_null":
325+
srctype = cwl.ArraySchema(items=srctype.items, type_="array")
326+
if (
327+
isinstance(srctype.items, MutableSequence)
328+
and "null" in srctype.items
329+
):
330+
srctype.items.remove("null")
331+
case "first_non_null" | "the_only_non_null":
332+
if (
333+
isinstance(srctype.items, MutableSequence)
334+
and "null" in srctype.items
335+
):
336+
srctype = [elem for elem in srctype.items if elem != "null"]
337+
case _:
338+
raise WorkflowException(
339+
f"Unrecognized pickValue enum {pickValue!r}"
340+
)
316341
if linkMerge is None:
317342
if can_assign_src_to_sink(srctype, sinktype, strict=True):
318343
return "pass"
@@ -321,10 +346,10 @@ def check_types(
321346
return "exception"
322347
if linkMerge == "merge_nested":
323348
return check_types(
324-
cwl.ArraySchema(items=srctype, type_="array"), sinktype, None, None
349+
cwl.ArraySchema(items=srctype, type_="array"), sinktype, None, None, None
325350
)
326351
if linkMerge == "merge_flattened":
327-
return check_types(merge_flatten_type(srctype), sinktype, None, None)
352+
return check_types(merge_flatten_type(srctype), sinktype, None, None, None)
328353
raise ValidationException(f"Invalid value {linkMerge} for linkMerge field.")
329354

330355

0 commit comments

Comments
 (0)