Skip to content

Commit 5377758

Browse files
GlassOfWhiskeymr-c
andauthored
use the new TypeDict types from cwl-utils 0.41 more (#2192)
Co-authored-by: Michael R. Crusoe <michael.crusoe@gmail.com>
1 parent 55223a6 commit 5377758

19 files changed

Lines changed: 340 additions & 301 deletions

cwltool/builder.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Builder(HasReqsHints):
9494
def __init__(
9595
self,
9696
job: CWLObjectType,
97-
files: list[CWLFileType | CWLDirectoryType],
97+
files: MutableSequence[CWLFileType | CWLDirectoryType],
9898
bindings: list[CWLObjectType],
9999
schemaDefs: MutableMapping[str, CWLObjectType],
100100
names: Names,
@@ -458,8 +458,8 @@ def _capture_files(f: CWLFileType) -> CWLFileType:
458458
if not found:
459459

460460
def addsf(
461-
files: MutableSequence[CWLObjectType],
462-
newsf: CWLObjectType,
461+
files: MutableSequence[CWLFileType | CWLDirectoryType],
462+
newsf: CWLFileType | CWLDirectoryType,
463463
) -> None:
464464
for f in files:
465465
if f["location"] == newsf["location"]:
@@ -469,23 +469,19 @@ def addsf(
469469

470470
if isinstance(sfname, MutableMapping):
471471
addsf(
472-
cast(
473-
MutableSequence[CWLObjectType],
474-
fdatum["secondaryFiles"],
475-
),
476-
sfname,
472+
fdatum["secondaryFiles"],
473+
cast(CWLFileType | CWLDirectoryType, sfname),
477474
)
478475
elif discover_secondaryFiles and self.fs_access.exists(sf_location):
479476
addsf(
480-
cast(
481-
MutableSequence[CWLObjectType],
482-
fdatum["secondaryFiles"],
477+
fdatum["secondaryFiles"],
478+
CWLFileType(
479+
**{
480+
"location": sf_location,
481+
"basename": sfname,
482+
"class": "File",
483+
}
483484
),
484-
{
485-
"location": sf_location,
486-
"basename": sfname,
487-
"class": "File",
488-
},
489485
)
490486
elif sf_required:
491487
raise SourceLine(

cwltool/checker.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from collections.abc import Iterator, MutableMapping, MutableSequence, Sized
44
from typing import Any, Literal, NamedTuple, Optional, Union, cast
55

6-
from cwl_utils.types import CWLObjectType, CWLOutputType
6+
from cwl_utils.types import CWLObjectType, CWLOutputType, SinkType
77
from schema_salad.exceptions import ValidationException
88
from schema_salad.sourceline import SourceLine, bullets, strip_dup_lineno
99
from schema_salad.utils import json_dumps
1010

1111
from .errors import WorkflowException
1212
from .loghandler import _logger
1313
from .process import shortname
14-
from .utils import SinkType, aslist
14+
from .utils import aslist
1515

1616

1717
def _get_type(tp: Any) -> Any:
@@ -22,8 +22,8 @@ def _get_type(tp: Any) -> Any:
2222

2323

2424
def check_types(
25-
srctype: SinkType,
26-
sinktype: SinkType,
25+
srctype: SinkType | None,
26+
sinktype: SinkType | None,
2727
linkMerge: str | None,
2828
pickValue: str | None,
2929
valueFrom: str | None,
@@ -83,18 +83,20 @@ def check_types(
8383
raise WorkflowException(f"Unrecognized linkMerge enum {linkMerge!r}")
8484

8585

86-
def merge_flatten_type(src: SinkType) -> CWLOutputType:
86+
def merge_flatten_type(src: SinkType | None) -> CWLOutputType | None:
8787
"""Return the merge flattened type of the source type."""
8888
match src:
8989
case MutableSequence():
90-
return [merge_flatten_type(cast(SinkType, t)) for t in src]
90+
return [merge_flatten_type(t) for t in src]
9191
case {"type": "array"}:
9292
return src
9393
case _:
9494
return {"items": src, "type": "array"}
9595

9696

97-
def can_assign_src_to_sink(src: SinkType, sink: SinkType | None, strict: bool = False) -> bool:
97+
def can_assign_src_to_sink(
98+
src: SinkType | None, sink: SinkType | None, strict: bool = False
99+
) -> bool:
98100
"""
99101
Check for identical type specifications, ignoring extra keys like inputBinding.
100102
@@ -112,8 +114,8 @@ def can_assign_src_to_sink(src: SinkType, sink: SinkType | None, strict: bool =
112114
return False
113115
if src["type"] == "array" and sink["type"] == "array":
114116
return can_assign_src_to_sink(
115-
cast(SinkType, src["items"]),
116-
cast(SinkType, sink["items"]),
117+
cast(MutableSequence[CWLOutputType | None], src["items"]),
118+
cast(MutableSequence[CWLOutputType | None], sink["items"]),
117119
strict,
118120
)
119121
if src["type"] == "record" and sink["type"] == "record":
@@ -128,15 +130,15 @@ def can_assign_src_to_sink(src: SinkType, sink: SinkType | None, strict: bool =
128130
if strict:
129131
return False
130132
return True
131-
return can_assign_src_to_sink(cast(SinkType, src["type"]), sink["type"], strict)
133+
return can_assign_src_to_sink(src["type"], sink["type"], strict)
132134
if isinstance(src, MutableSequence):
133135
if strict:
134136
for this_src in src:
135-
if not can_assign_src_to_sink(cast(SinkType, this_src), sink):
137+
if not can_assign_src_to_sink(this_src, sink):
136138
return False
137139
return True
138140
for this_src in src:
139-
if this_src != "null" and can_assign_src_to_sink(cast(SinkType, this_src), sink):
141+
if this_src != "null" and can_assign_src_to_sink(this_src, sink):
140142
return True
141143
return False
142144
if isinstance(sink, MutableSequence):

0 commit comments

Comments
 (0)