Skip to content
Merged
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: 6 additions & 8 deletions cwltool/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check_types(
def merge_flatten_type(src: SinkType) -> CWLOutputType:
"""Return the merge flattened type of the source type."""
if isinstance(src, MutableSequence):
return [merge_flatten_type(cast(SinkType, t)) for t in src]
return [merge_flatten_type(t) for t in src]
if isinstance(src, MutableMapping) and src.get("type") == "array":
return src
return {"items": src, "type": "array"}
Expand Down Expand Up @@ -94,22 +94,20 @@ def can_assign_src_to_sink(src: SinkType, sink: Optional[SinkType], strict: bool
if strict:
return False
return True
return can_assign_src_to_sink(
cast(SinkType, src["type"]), cast(Optional[SinkType], sink["type"]), strict
)
return can_assign_src_to_sink(src["type"], sink["type"], strict)
if isinstance(src, MutableSequence):
if strict:
for this_src in src:
if not can_assign_src_to_sink(cast(SinkType, this_src), sink):
if not can_assign_src_to_sink(this_src, sink):
return False
return True
for this_src in src:
if this_src != "null" and can_assign_src_to_sink(cast(SinkType, this_src), sink):
if this_src != "null" and can_assign_src_to_sink(this_src, sink):
return True
return False
if isinstance(sink, MutableSequence):
for this_sink in sink:
if can_assign_src_to_sink(src, cast(SinkType, this_sink)):
if can_assign_src_to_sink(src, this_sink):
return True
return False
return bool(src == sink)
Expand Down Expand Up @@ -257,7 +255,7 @@ def static_checker(
)
+ "\n"
+ SourceLine(sink, "type").makeError(
" with sink '%s' of type %s" % (sink_name, json_dumps(sink["type"]))
" with sink '{}' of type {}".format(sink_name, json_dumps(sink["type"]))
)
)
if linkMerge is not None:
Expand Down
4 changes: 2 additions & 2 deletions cwltool/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def _initialworkdir(self, j: Optional[JobBase], builder: Builder) -> None:
if not isinstance(ls_evaluated, MutableSequence):
fail = ls_evaluated
else:
ls_evaluated2 = cast(MutableSequence[Union[None, CWLOutputType]], ls_evaluated)
ls_evaluated2 = ls_evaluated
for entry in ls_evaluated2:
if entry == None: # noqa
if classic_dirent:
Expand Down Expand Up @@ -1389,7 +1389,7 @@ def collect_output(
"Multiple matches for output item that is a single file."
)
else:
result = cast(CWLOutputType, result[0])
result = result[0]

if "secondaryFiles" in schema:
with SourceLine(schema, "secondaryFiles", WorkflowException, debug):
Expand Down
4 changes: 2 additions & 2 deletions cwltool/cwlprov/ro.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,12 +674,12 @@ def _relativise_files(

for val in structure.values():
try:
self._relativise_files(cast(CWLOutputType, val))
self._relativise_files(val)
except OSError:
pass
return

if isinstance(structure, MutableSequence):
for obj in structure:
# Recurse and rewrite any nested File objects
self._relativise_files(cast(CWLOutputType, obj))
self._relativise_files(obj)
7 changes: 5 additions & 2 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def realize_input_schema(
if isinstance(entry["type"], Mapping):
entry["type"] = cast(
CWLOutputType,
realize_input_schema([cast(CWLObjectType, entry["type"])], schema_defs),
realize_input_schema([entry["type"]], schema_defs),
)
if entry["type"] == "array":
items = entry["items"] if not isinstance(entry["items"], str) else [entry["items"]]
Expand Down Expand Up @@ -373,7 +373,10 @@ def load_job_order(
content_types=CWL_CONTENT_TYPES,
)

if job_order_object is not None and "http://commonwl.org/cwltool#overrides" in job_order_object:
if (
isinstance(job_order_object, CommentedMap)
and "http://commonwl.org/cwltool#overrides" in job_order_object
):
ov_uri = file_uri(job_order_file or input_basedir)
overrides_list.extend(resolve_overrides(job_order_object, ov_uri, tool_file_uri))
del job_order_object["http://commonwl.org/cwltool#overrides"]
Expand Down
8 changes: 4 additions & 4 deletions cwltool/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def find_run(
runs.add(d["run"])
find_run(loadref(None, d["run"]), loadref, runs)
for s in d.values():
find_run(s, loadref, runs)
find_run(cast(Union[CWLObjectType, ResolveType], s), loadref, runs)


def find_ids(
Expand All @@ -47,7 +47,7 @@ def find_ids(
if i in d and isinstance(d[i], str):
ids.add(cast(str, d[i]))
for s2 in d.values():
find_ids(cast(CWLOutputType, s2), ids)
find_ids(s2, ids)


def replace_refs(d: Any, rewrite: dict[str, str], stem: str, newstem: str) -> None:
Expand Down Expand Up @@ -84,7 +84,7 @@ def import_embed(
) -> None:
if isinstance(d, MutableSequence):
for v in d:
import_embed(cast(CWLOutputType, v), seen)
import_embed(v, seen)
elif isinstance(d, MutableMapping):
for n in ("id", "name"):
if n in d:
Expand All @@ -100,7 +100,7 @@ def import_embed(
break

for k in sorted(d.keys()):
import_embed(cast(CWLOutputType, d[k]), seen)
import_embed(d[k], seen)


def pack(
Expand Down
6 changes: 3 additions & 3 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def avroize_type(
cast(MutableSequence[CWLOutputType], field_type["items"]), name_prefix
)
else:
field_type["type"] = avroize_type(cast(CWLOutputType, field_type["type"]), name_prefix)
field_type["type"] = avroize_type(field_type["type"], name_prefix)
elif field_type == "File":
return "org.w3id.cwl.cwl.File"
elif field_type == "Directory":
Expand Down Expand Up @@ -490,10 +490,10 @@ def var_spool_cwl_detector(
r = True
elif isinstance(obj, MutableMapping):
for mkey, mvalue in obj.items():
r = var_spool_cwl_detector(cast(CWLOutputType, mvalue), obj, mkey) or r
r = var_spool_cwl_detector(mvalue, obj, mkey) or r
elif isinstance(obj, MutableSequence):
for lkey, lvalue in enumerate(obj):
r = var_spool_cwl_detector(cast(CWLOutputType, lvalue), obj, lkey) or r
r = var_spool_cwl_detector(lvalue, obj, lkey) or r
return r


Expand Down
10 changes: 5 additions & 5 deletions cwltool/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import uuid
from collections.abc import MutableMapping, MutableSequence
from typing import Optional, cast
from typing import Optional

from .utils import CWLObjectType, CWLOutputType

Expand Down Expand Up @@ -43,11 +43,11 @@ def has_secret(self, value: CWLOutputType) -> bool:
return True
elif isinstance(value, MutableMapping):
for this_value in value.values():
if self.has_secret(cast(CWLOutputType, this_value)):
if self.has_secret(this_value):
return True
elif isinstance(value, MutableSequence):
for this_value in value:
if self.has_secret(cast(CWLOutputType, this_value)):
if self.has_secret(this_value):
return True
return False

Expand All @@ -58,7 +58,7 @@ def retrieve(self, value: CWLOutputType) -> CWLOutputType:
value = value.replace(key, this_value)
return value
elif isinstance(value, MutableMapping):
return {k: self.retrieve(cast(CWLOutputType, v)) for k, v in value.items()}
return {k: self.retrieve(v) for k, v in value.items()}
elif isinstance(value, MutableSequence):
return [self.retrieve(cast(CWLOutputType, v)) for v in value]
return [self.retrieve(v) for v in value]
return value
2 changes: 1 addition & 1 deletion cwltool/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
new_seq[index] = update_secondaryFiles(entry)
return new_seq
elif isinstance(t, MutableSequence):
return CommentedSeq([update_secondaryFiles(cast(CWLOutputType, p)) for p in t])
return CommentedSeq([update_secondaryFiles(p) for p in t])

Check warning on line 135 in cwltool/update.py

View check run for this annotation

Codecov / codecov/patch

cwltool/update.py#L135

Added line #L135 was not covered by tests
elif isinstance(t, MutableMapping):
return cast(MutableMapping[str, str], t)
elif top:
Expand Down
2 changes: 1 addition & 1 deletion mypy-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mypy==1.15.0 # also update pyproject.toml
mypy==1.16.0 # also update pyproject.toml
ruamel.yaml>=0.16.0,<0.19
cwl-utils>=0.32
cwltest
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = [
"setuptools>=45",
"setuptools_scm[toml]>=8.0.4,<9",
"mypy==1.15.0", # also update mypy-requirements.txt
"mypy==1.16.0", # also update mypy-requirements.txt
"types-requests",
"types-psutil",
"importlib_resources>=1.4;python_version<'3.9'",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _find_package_data(base: str, globs: list[str], root: str = "cwltool") -> li
mypyc_targets = [x for x in all_real_pys if x not in mypyc_skiplist]

# Strip out any test code
mypyc_targets = [x for x in mypyc_targets if not x.startswith(("tests" + os.sep))]
mypyc_targets = [x for x in mypyc_targets if not x.startswith("tests" + os.sep)]

mypyc_targets.sort()

Expand Down
9 changes: 5 additions & 4 deletions tests/test_context.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging
import subprocess
import sys
import logging
from io import StringIO
from typing import MutableMapping, cast
from pathlib import Path
from typing import cast
from collections.abc import MutableMapping

from cwltool.context import RuntimeContext
from cwltool.factory import Factory
from cwltool.utils import CWLObjectType
from cwltool.workflow_job import WorkflowJobStep
from pathlib import Path

from .util import get_data, needs_docker

Expand Down Expand Up @@ -49,7 +50,7 @@ def test_workflow_job_step_name_callback() -> None:
def step_name_hook(step: WorkflowJobStep, job: CWLObjectType) -> str:
j1 = cast(MutableMapping[str, CWLObjectType], job)
inp = cast(MutableMapping[str, str], j1.get("revtool_input", j1.get("sorted_input")))
return "%s on %s" % (
return "{} on {}".format(
step.name,
inp.get("basename"),
)
Expand Down