Skip to content

Commit 1ed986c

Browse files
Fix typing errors in utils
1 parent 9fbb611 commit 1ed986c

File tree

5 files changed

+134
-70
lines changed

5 files changed

+134
-70
lines changed

cwl_utils/parser/cwl_v1_0_utils.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import MutableMapping, MutableSequence, Sequence
66
from io import StringIO
77
from pathlib import Path
8-
from typing import IO, Any, cast
8+
from typing import Any, IO, cast
99
from urllib.parse import urldefrag
1010

1111
from schema_salad.exceptions import ValidationException
@@ -181,7 +181,7 @@ def can_assign_src_to_sink(src: Any, sink: Any, strict: bool = False) -> bool:
181181

182182
def check_all_types(
183183
src_dict: dict[str, Any],
184-
sinks: MutableSequence[cwl.WorkflowStepInput | cwl.WorkflowOutputParameter],
184+
sinks: Sequence[cwl.WorkflowStepInput | cwl.WorkflowOutputParameter],
185185
type_dict: dict[str, Any],
186186
) -> dict[str, list[SrcSink]]:
187187
"""Given a list of sinks, check if their types match with the types of their sources."""
@@ -197,7 +197,7 @@ def check_all_types(
197197
case _:
198198
continue
199199
if sourceField is not None:
200-
if isinstance(sourceField, MutableSequence):
200+
if isinstance(sourceField, Sequence):
201201
linkMerge = sink.linkMerge or (
202202
"merge_nested" if len(sourceField) > 1 else None
203203
)
@@ -475,14 +475,26 @@ def param_for_source_id(
475475
parent: cwl.Workflow | None = None,
476476
scatter_context: list[tuple[int, str] | None] | None = None,
477477
) -> (
478-
cwl.InputParameter
479-
| cwl.CommandOutputParameter
480-
| MutableSequence[cwl.InputParameter | cwl.CommandOutputParameter]
478+
cwl.CommandOutputParameter
479+
| cwl.ExpressionToolOutputParameter
480+
| cwl.InputParameter
481+
| cwl.WorkflowOutputParameter
482+
| MutableSequence[
483+
cwl.CommandOutputParameter
484+
| cwl.ExpressionToolOutputParameter
485+
| cwl.InputParameter
486+
| cwl.WorkflowOutputParameter
487+
]
481488
):
482489
"""Find the process input parameter that matches one of the given sourcenames."""
483490
if isinstance(sourcenames, str):
484491
sourcenames = [sourcenames]
485-
params: MutableSequence[cwl.InputParameter | cwl.CommandOutputParameter] = []
492+
params: MutableSequence[
493+
cwl.CommandOutputParameter
494+
| cwl.ExpressionToolOutputParameter
495+
| cwl.InputParameter
496+
| cwl.WorkflowOutputParameter
497+
] = []
486498
for sourcename in sourcenames:
487499
if not isinstance(process, cwl.Workflow):
488500
for param in process.inputs:

cwl_utils/parser/cwl_v1_1_utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import hashlib
33
import logging
44
from collections import namedtuple
5-
from collections.abc import MutableMapping, MutableSequence
5+
from collections.abc import MutableMapping, MutableSequence, Sequence
66
from io import StringIO
77
from pathlib import Path
88
from typing import Any, IO, cast
@@ -181,7 +181,7 @@ def can_assign_src_to_sink(src: Any, sink: Any, strict: bool = False) -> bool:
181181

182182
def check_all_types(
183183
src_dict: dict[str, Any],
184-
sinks: MutableSequence[cwl.WorkflowStepInput | cwl.WorkflowOutputParameter],
184+
sinks: Sequence[cwl.WorkflowStepInput | cwl.WorkflowOutputParameter],
185185
type_dict: dict[str, Any],
186186
) -> dict[str, list[SrcSink]]:
187187
"""Given a list of sinks, check if their types match with the types of their sources."""
@@ -197,7 +197,7 @@ def check_all_types(
197197
case _:
198198
continue
199199
if sourceField is not None:
200-
if isinstance(sourceField, MutableSequence):
200+
if isinstance(sourceField, Sequence):
201201
linkMerge = sink.linkMerge or (
202202
"merge_nested" if len(sourceField) > 1 else None
203203
)
@@ -489,11 +489,15 @@ def param_for_source_id(
489489
) -> (
490490
cwl.CommandInputParameter
491491
| cwl.CommandOutputParameter
492+
| cwl.ExpressionToolOutputParameter
492493
| cwl.WorkflowInputParameter
494+
| cwl.WorkflowOutputParameter
493495
| MutableSequence[
494496
cwl.CommandInputParameter
495497
| cwl.CommandOutputParameter
498+
| cwl.ExpressionToolOutputParameter
496499
| cwl.WorkflowInputParameter
500+
| cwl.WorkflowOutputParameter
497501
]
498502
):
499503
"""Find the process input parameter that matches one of the given sourcenames."""
@@ -502,7 +506,9 @@ def param_for_source_id(
502506
params: MutableSequence[
503507
cwl.CommandInputParameter
504508
| cwl.CommandOutputParameter
509+
| cwl.ExpressionToolOutputParameter
505510
| cwl.WorkflowInputParameter
511+
| cwl.WorkflowOutputParameter
506512
] = []
507513
for sourcename in sourcenames:
508514
if not isinstance(process, cwl.Workflow):

cwl_utils/parser/cwl_v1_2_utils.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import hashlib
33
import logging
44
from collections import namedtuple
5-
from collections.abc import MutableMapping, MutableSequence
5+
from collections.abc import Mapping, MutableMapping, MutableSequence, Sequence
66
from io import StringIO
77
from pathlib import Path
88
from typing import Any, IO, cast
@@ -83,7 +83,7 @@ def _compare_type(type1: Any, type2: Any) -> bool:
8383

8484

8585
def _is_all_output_method_loop_step(
86-
param_to_step: dict[str, cwl.WorkflowStep], parm_id: str
86+
param_to_step: Mapping[str, cwl.WorkflowStep], parm_id: str
8787
) -> bool:
8888
if (source_step := param_to_step.get(parm_id)) is not None:
8989
for requirement in source_step.requirements or []:
@@ -93,7 +93,7 @@ def _is_all_output_method_loop_step(
9393

9494

9595
def _is_conditional_step(
96-
param_to_step: dict[str, cwl.WorkflowStep], parm_id: str
96+
param_to_step: Mapping[str, cwl.WorkflowStep], parm_id: str
9797
) -> bool:
9898
if (source_step := param_to_step.get(parm_id)) is not None:
9999
if source_step.when is not None:
@@ -200,8 +200,8 @@ def can_assign_src_to_sink(src: Any, sink: Any, strict: bool = False) -> bool:
200200

201201
def check_all_types(
202202
src_dict: dict[str, Any],
203-
sinks: MutableSequence[cwl.WorkflowStepInput | cwl.WorkflowOutputParameter],
204-
param_to_step: dict[str, cwl.WorkflowStep],
203+
sinks: Sequence[cwl.WorkflowStepInput | cwl.WorkflowOutputParameter],
204+
param_to_step: Mapping[str, cwl.WorkflowStep],
205205
type_dict: dict[str, Any],
206206
) -> dict[str, list[SrcSink]]:
207207
"""Given a list of sinks, check if their types match with the types of their sources."""
@@ -220,7 +220,7 @@ def check_all_types(
220220
case _:
221221
continue
222222
if sourceField is not None:
223-
if isinstance(sourceField, MutableSequence):
223+
if isinstance(sourceField, Sequence):
224224
linkMerge: str | None = sink.linkMerge or (
225225
"merge_nested" if len(sourceField) > 1 else None
226226
)
@@ -578,11 +578,19 @@ def param_for_source_id(
578578
) -> (
579579
cwl.CommandInputParameter
580580
| cwl.CommandOutputParameter
581+
| cwl.ExpressionToolOutputParameter
582+
| cwl.OperationInputParameter
583+
| cwl.OperationOutputParameter
581584
| cwl.WorkflowInputParameter
585+
| cwl.WorkflowOutputParameter
582586
| MutableSequence[
583587
cwl.CommandInputParameter
584588
| cwl.CommandOutputParameter
589+
| cwl.ExpressionToolOutputParameter
590+
| cwl.OperationInputParameter
591+
| cwl.OperationOutputParameter
585592
| cwl.WorkflowInputParameter
593+
| cwl.WorkflowOutputParameter
586594
]
587595
):
588596
"""Find the process input parameter that matches one of the given sourcenames."""
@@ -591,7 +599,9 @@ def param_for_source_id(
591599
params: MutableSequence[
592600
cwl.CommandInputParameter
593601
| cwl.CommandOutputParameter
602+
| cwl.ExpressionToolOutputParameter
594603
| cwl.WorkflowInputParameter
604+
| cwl.WorkflowOutputParameter
595605
] = []
596606
for sourcename in sourcenames:
597607
if not isinstance(process, cwl.Workflow):

0 commit comments

Comments
 (0)