From 641de7aaf737c300ddb8d34410f6bd1fec8d8ad6 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Wed, 15 Nov 2023 11:39:57 +0100 Subject: [PATCH] Drop "Atomic" types in favor of recursive typedefs --- cwltool/checker.py | 6 +++--- cwltool/main.py | 13 ++++++------- cwltool/process.py | 7 +++---- cwltool/utils.py | 24 +++++------------------- 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/cwltool/checker.py b/cwltool/checker.py index c11561719..4070af991 100644 --- a/cwltool/checker.py +++ b/cwltool/checker.py @@ -21,7 +21,7 @@ from .errors import WorkflowException from .loghandler import _logger from .process import shortname -from .utils import CWLObjectType, CWLOutputAtomType, CWLOutputType, SinkType, aslist +from .utils import CWLObjectType, CWLOutputType, SinkType, aslist def _get_type(tp): @@ -90,8 +90,8 @@ def can_assign_src_to_sink(src: SinkType, sink: Optional[SinkType], strict: bool return False if src["type"] == "array" and sink["type"] == "array": return can_assign_src_to_sink( - cast(MutableSequence[CWLOutputAtomType], src["items"]), - cast(MutableSequence[CWLOutputAtomType], sink["items"]), + cast(MutableSequence[CWLOutputType], src["items"]), + cast(MutableSequence[CWLOutputType], sink["items"]), strict, ) if src["type"] == "record" and sink["type"] == "record": diff --git a/cwltool/main.py b/cwltool/main.py index 0950059e6..6a8e86d12 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -105,7 +105,6 @@ from .utils import ( DEFAULT_TMP_PREFIX, CWLObjectType, - CWLOutputAtomType, CWLOutputType, HasReqsHints, adjustDirObjs, @@ -289,7 +288,7 @@ def realize_input_schema( _, input_type_name = entry["type"].split("#") if input_type_name in schema_defs: entry["type"] = cast( - CWLOutputAtomType, + CWLOutputType, realize_input_schema( cast( MutableSequence[Union[str, CWLObjectType]], @@ -300,7 +299,7 @@ def realize_input_schema( ) if isinstance(entry["type"], MutableSequence): entry["type"] = cast( - CWLOutputAtomType, + CWLOutputType, realize_input_schema( cast(MutableSequence[Union[str, CWLObjectType]], entry["type"]), schema_defs, @@ -308,13 +307,13 @@ def realize_input_schema( ) if isinstance(entry["type"], Mapping): entry["type"] = cast( - CWLOutputAtomType, + CWLOutputType, realize_input_schema([cast(CWLObjectType, entry["type"])], schema_defs), ) if entry["type"] == "array": items = entry["items"] if not isinstance(entry["items"], str) else [entry["items"]] entry["items"] = cast( - CWLOutputAtomType, + CWLOutputType, realize_input_schema( cast(MutableSequence[Union[str, CWLObjectType]], items), schema_defs, @@ -322,7 +321,7 @@ def realize_input_schema( ) if entry["type"] == "record": entry["fields"] = cast( - CWLOutputAtomType, + CWLOutputType, realize_input_schema( cast(MutableSequence[Union[str, CWLObjectType]], entry["fields"]), schema_defs, @@ -612,7 +611,7 @@ def loadref(base: str, uri: str) -> Union[CommentedMap, CommentedSeq, str, None] nestdirs=nestdirs, ) if sfs is not None: - deps["secondaryFiles"] = cast(MutableSequence[CWLOutputAtomType], mergedirs(sfs)) + deps["secondaryFiles"] = cast(MutableSequence[CWLOutputType], mergedirs(sfs)) return deps diff --git a/cwltool/process.py b/cwltool/process.py index 80d70be74..7072d5c08 100644 --- a/cwltool/process.py +++ b/cwltool/process.py @@ -61,7 +61,6 @@ from .update import INTERNAL_VERSION, ORDERED_VERSIONS, ORIGINAL_CWLVERSION from .utils import ( CWLObjectType, - CWLOutputAtomType, CWLOutputType, HasReqsHints, JobsGeneratorType, @@ -1146,7 +1145,7 @@ def mergedirs( for e in ents.values(): if e["class"] == "Directory" and "listing" in e: e["listing"] = cast( - MutableSequence[CWLOutputAtomType], + MutableSequence[CWLOutputType], mergedirs(cast(List[CWLObjectType], e["listing"])), ) r.extend(ents.values()) @@ -1206,7 +1205,7 @@ def scandeps( deps["listing"] = doc["listing"] if doc["class"] == "File" and "secondaryFiles" in doc: deps["secondaryFiles"] = cast( - CWLOutputAtomType, + CWLOutputType, scandeps( base, cast( @@ -1290,7 +1289,7 @@ def scandeps( ) if sf: deps2["secondaryFiles"] = cast( - MutableSequence[CWLOutputAtomType], mergedirs(sf) + MutableSequence[CWLOutputType], mergedirs(sf) ) if nestdirs: deps2 = nestdir(base, deps2) diff --git a/cwltool/utils.py b/cwltool/utils.py index 165492feb..aa25c171c 100644 --- a/cwltool/utils.py +++ b/cwltool/utils.py @@ -67,27 +67,14 @@ processes_to_kill: Deque["subprocess.Popen[str]"] = collections.deque() -CWLOutputAtomType = Union[ - None, - bool, - str, - int, - float, - MutableSequence[ - Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]] - ], - MutableMapping[ - str, - Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]], - ], -] CWLOutputType = Union[ + None, bool, str, int, float, - MutableSequence[CWLOutputAtomType], - MutableMapping[str, CWLOutputAtomType], + MutableSequence["CWLOutputType"], + MutableMapping[str, "CWLOutputType"], ] CWLObjectType = MutableMapping[str, Optional[CWLOutputType]] """Typical raw dictionary found in lightly parsed CWL.""" @@ -103,8 +90,7 @@ DirectoryType = TypedDict( "DirectoryType", {"class": str, "listing": List[CWLObjectType], "basename": str} ) -JSONAtomType = Union[Dict[str, Any], List[Any], str, int, float, bool, None] -JSONType = Union[Dict[str, JSONAtomType], List[JSONAtomType], str, int, float, bool, None] +JSONType = Union[Dict[str, "JSONType"], List["JSONType"], str, int, float, bool, None] class WorkflowStateItem(NamedTuple): @@ -297,7 +283,7 @@ def get_listing(fs_access: "StdFsAccess", rec: CWLObjectType, recursive: bool = return if "listing" in rec: return - listing: List[CWLOutputAtomType] = [] + listing: List[CWLOutputType] = [] loc = cast(str, rec["location"]) for ld in fs_access.listdir(loc): parse = urllib.parse.urlparse(ld)