From 10a914bf2c0753665189ca99668e51ee660845e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 May 2025 07:23:14 +0000 Subject: [PATCH 1/2] Bump mypy from 1.15.0 to 1.16.0 Bumps [mypy](https://github.com/python/mypy) from 1.15.0 to 1.16.0. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v1.15.0...v1.16.0) --- updated-dependencies: - dependency-name: mypy dependency-version: 1.16.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- mypy-requirements.txt | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy-requirements.txt b/mypy-requirements.txt index 65e517172..3dc19c4e3 100644 --- a/mypy-requirements.txt +++ b/mypy-requirements.txt @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 35db6cf42..222d23159 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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'", From 4b78c43e4763fae12c9b206c96e4d7b47f93cb3b Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Fri, 30 May 2025 14:53:54 +0200 Subject: [PATCH 2/2] mypy 1.16 type simplifications --- cwltool/checker.py | 14 ++++++-------- cwltool/command_line_tool.py | 4 ++-- cwltool/cwlprov/ro.py | 4 ++-- cwltool/main.py | 7 +++++-- cwltool/pack.py | 8 ++++---- cwltool/process.py | 6 +++--- cwltool/secrets.py | 10 +++++----- cwltool/update.py | 2 +- setup.py | 2 +- tests/test_context.py | 9 +++++---- 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/cwltool/checker.py b/cwltool/checker.py index a3b8ba5df..b3637db20 100644 --- a/cwltool/checker.py +++ b/cwltool/checker.py @@ -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"} @@ -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) @@ -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: diff --git a/cwltool/command_line_tool.py b/cwltool/command_line_tool.py index cbff45bd0..eb7bf9e23 100644 --- a/cwltool/command_line_tool.py +++ b/cwltool/command_line_tool.py @@ -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: @@ -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): diff --git a/cwltool/cwlprov/ro.py b/cwltool/cwlprov/ro.py index be10d3d64..19334d2b8 100644 --- a/cwltool/cwlprov/ro.py +++ b/cwltool/cwlprov/ro.py @@ -674,7 +674,7 @@ def _relativise_files( for val in structure.values(): try: - self._relativise_files(cast(CWLOutputType, val)) + self._relativise_files(val) except OSError: pass return @@ -682,4 +682,4 @@ def _relativise_files( 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) diff --git a/cwltool/main.py b/cwltool/main.py index b317ff27a..f68d05052 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -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"]] @@ -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"] diff --git a/cwltool/pack.py b/cwltool/pack.py index d3705d5e4..6d96c83a1 100644 --- a/cwltool/pack.py +++ b/cwltool/pack.py @@ -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( @@ -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: @@ -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: @@ -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( diff --git a/cwltool/process.py b/cwltool/process.py index bc2aaf145..ce0f52b73 100644 --- a/cwltool/process.py +++ b/cwltool/process.py @@ -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": @@ -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 diff --git a/cwltool/secrets.py b/cwltool/secrets.py index c73e0108c..3d54774e1 100644 --- a/cwltool/secrets.py +++ b/cwltool/secrets.py @@ -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 @@ -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 @@ -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 diff --git a/cwltool/update.py b/cwltool/update.py index 67e1f4257..290498031 100644 --- a/cwltool/update.py +++ b/cwltool/update.py @@ -132,7 +132,7 @@ def update_secondaryFiles( 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]) elif isinstance(t, MutableMapping): return cast(MutableMapping[str, str], t) elif top: diff --git a/setup.py b/setup.py index 57eb06407..e1e7510b8 100644 --- a/setup.py +++ b/setup.py @@ -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() diff --git a/tests/test_context.py b/tests/test_context.py index be1d89575..5f3666ce9 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -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 @@ -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"), )