Skip to content

Commit 663702e

Browse files
committed
more type updates
1 parent aac882e commit 663702e

File tree

8 files changed

+54
-50
lines changed

8 files changed

+54
-50
lines changed

cwltool/builder.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from rdflib import Graph, URIRef # pylint: disable=unused-import
1111
from rdflib.namespace import OWL, RDFS
12+
from ruamel.yaml.comments import CommentedMap
1213
import schema_salad.schema # pylint: disable=unused-import
1314
from schema_salad import validate
1415
from schema_salad.schema import AvroSchemaFromJSONData
@@ -195,22 +196,23 @@ def build_job_script(self, commands):
195196
return None
196197

197198
def bind_input(self,
198-
schema, # type: Dict[Text, Any]
199+
schema, # type: MutableMapping[Text, Any]
199200
datum, # type: Any
200201
discover_secondaryFiles, # type: bool
201202
lead_pos=None, # type: Optional[Union[int, List[int]]]
202203
tail_pos=None, # type: Optional[List[int]]
203-
): # type: (...) -> List[Dict[Text, Any]]
204+
): # type: (...) -> List[MutableMapping[Text, Any]]
204205

205206
if tail_pos is None:
206207
tail_pos = []
207208
if lead_pos is None:
208209
lead_pos = []
209-
bindings = [] # type: List[Dict[Text,Text]]
210-
binding = None # type: Optional[Dict[Text,Any]]
210+
bindings = [] # type: List[MutableMapping[Text, Text]]
211+
binding = None # type: Optional[MutableMapping[Text,Any]]
211212
value_from_expression = False
212213
if "inputBinding" in schema and isinstance(schema["inputBinding"], MutableMapping):
213-
binding = copy.deepcopy(schema["inputBinding"])
214+
binding = CommentedMap(schema["inputBinding"].items())
215+
assert binding is not None
214216

215217
if "position" in binding:
216218
binding["position"] = aslist(lead_pos) + aslist(binding["position"]) + aslist(tail_pos)
@@ -373,7 +375,7 @@ def generate_arg(self, binding): # type: (Dict[Text, Any]) -> List[Text]
373375
with SourceLine(binding, "separate", WorkflowException, _logger.isEnabledFor(logging.DEBUG)):
374376
raise WorkflowException("'separate' option can not be specified without prefix")
375377

376-
argl = [] # type: List[Dict[Text,Text]]
378+
argl = [] # type: MutableSequence[MutableMapping[Text, Text]]
377379
if isinstance(value, MutableSequence):
378380
if binding.get("itemSeparator") and value:
379381
argl = [binding["itemSeparator"].join([self.tostr(v) for v in value])]

cwltool/checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ def can_assign_src_to_sink(src, sink, strict=False): # type: (Any, Any, bool) -
100100

101101

102102
def _compare_records(src, sink, strict=False):
103-
# type: (Dict[Text, Any], Dict[Text, Any], bool) -> bool
103+
# type: (MutableMapping[Text, Any], MutableMapping[Text, Any], bool) -> bool
104104
"""Compare two records, ensuring they have compatible fields.
105105
106106
This handles normalizing record names, which will be relative to workflow
107107
step, so that they can be compared.
108108
"""
109109

110-
def _rec_fields(rec): # type: (Dict[Text, Any]) -> Dict[Text, Any]
110+
def _rec_fields(rec): # type: (MutableMapping[Text, Any]) -> MutableMapping[Text, Any]
111111
out = {}
112112
for field in rec["fields"]:
113113
name = shortname(field["name"])

cwltool/command_line_tool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def run(self, runtimeContext): # type: (RuntimeContext) -> None
9999
self.output_callback({}, "permanentFail")
100100

101101
def job(self,
102-
job_order, # type: Dict[Text, Text]
102+
job_order, # type: MutableMapping[Text, Text]
103103
output_callbacks, # type: Callable[[Any, Any], Any]
104104
runtimeContext # type: RuntimeContext
105105
):
@@ -222,7 +222,7 @@ def check_valid_locations(fs_access, ob):
222222

223223
class CommandLineTool(Process):
224224
def __init__(self, toolpath_object, loadingContext):
225-
# type: (Dict[Text, Any], LoadingContext) -> None
225+
# type: (MutableMapping[Text, Any], LoadingContext) -> None
226226
super(CommandLineTool, self).__init__(toolpath_object, loadingContext)
227227
self.prov_obj = loadingContext.prov_obj
228228

@@ -272,7 +272,7 @@ def updatePathmap(self, outdir, pathmap, fn):
272272
self.updatePathmap(os.path.join(outdir, fn["basename"]), pathmap, ls)
273273

274274
def job(self,
275-
job_order, # type: Dict[Text, Text]
275+
job_order, # type: MutableMapping[Text, Text]
276276
output_callbacks, # type: Callable[[Any, Any], Any]
277277
runtimeContext # RuntimeContext
278278
):

cwltool/context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import copy
22
import threading # pylint: disable=unused-import
3-
from typing import Any, Callable, Dict, Iterable, List, Optional
3+
from typing import Any, Callable, Dict, Iterable, List, MutableMapping, Optional
44
from typing_extensions import Text, TYPE_CHECKING # pylint: disable=unused-import
55
# move to a regular typing import when Python 3.3-3.6 is no longer supported
66
from schema_salad.ref_resolver import ( # pylint: disable=unused-import
@@ -27,13 +27,13 @@ def __init__(self, kwargs=None):
2727
if hasattr(self, k):
2828
setattr(self, k, v)
2929

30-
def make_tool_notimpl(toolpath_object, # type: Dict[Text, Any]
30+
def make_tool_notimpl(toolpath_object, # type: MutableMapping[Text, Any]
3131
loadingContext # type: LoadingContext
3232
): # type: (...) -> Process
3333
raise NotImplementedError()
3434

3535

36-
default_make_tool = make_tool_notimpl # type: Callable[[Dict[Text, Any], LoadingContext], Process]
36+
default_make_tool = make_tool_notimpl # type: Callable[[MutableMapping[Text, Any], LoadingContext], Process]
3737

3838
class LoadingContext(ContextBase):
3939

@@ -113,7 +113,7 @@ def __init__(self, kwargs=None):
113113
self.job_script_provider = None # type: Optional[DependenciesConfiguration]
114114
self.select_resources = None # type: Optional[select_resources_callable]
115115
self.eval_timeout = 20 # type: float
116-
self.postScatterEval = None # type: Optional[Callable[[Dict[Text, Any]], Dict[Text, Any]]]
116+
self.postScatterEval = None # type: Optional[Callable[[MutableMapping[Text, Any]], Dict[Text, Any]]]
117117
self.on_error = "stop" # type: Text
118118
self.strict_memory_limit = False # type: bool
119119

cwltool/process.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def get_overrides(overrides, toolid): # type: (List[Dict[Text, Any]], Text) ->
446446
""")
447447

448448

449-
def var_spool_cwl_detector(obj, # type: Union[Dict, List, Text]
449+
def var_spool_cwl_detector(obj, # type: Union[MutableMapping, List, Text]
450450
item=None, # type: Optional[Any]
451451
obj_key=None, # type: Optional[Any]
452452
): # type: (...)->bool
@@ -474,7 +474,7 @@ def eval_resource(builder, resource_req): # type: (Builder, Text) -> Any
474474

475475
class Process(six.with_metaclass(abc.ABCMeta, HasReqsHints)):
476476
def __init__(self,
477-
toolpath_object, # type: Dict[Text, Any]
477+
toolpath_object, # type: MutableMapping[Text, Any]
478478
loadingContext # type: LoadingContext
479479
): # type: (...) -> None
480480
self.metadata = getdefault(loadingContext.metadata, {}) # type: Dict[Text,Any]
@@ -604,7 +604,7 @@ def __init__(self,
604604
var_spool_cwl_detector(self.tool)
605605

606606
def _init_job(self, joborder, runtimeContext):
607-
# type: (Dict[Text, Text], RuntimeContext) -> Builder
607+
# type: (MutableMapping[Text, Text], RuntimeContext) -> Builder
608608

609609
job = cast(Dict[Text, Union[Dict[Text, Any], List[Any], Text, None]],
610610
copy.deepcopy(joborder))
@@ -788,12 +788,12 @@ def validate_hints(self, avsc_names, hints, strict):
788788
else:
789789
_logger.info(sl.makeError(u"Unknown hint %s" % (r["class"])))
790790

791-
def visit(self, op): # type: (Callable[[Dict[Text, Any]], None]) -> None
791+
def visit(self, op): # type: (Callable[[MutableMapping[Text, Any]], None]) -> None
792792
op(self.tool)
793793

794794
@abc.abstractmethod
795795
def job(self,
796-
job_order, # type: Dict[Text, Text]
796+
job_order, # type: MutableMapping[Text, Text]
797797
output_callbacks, # type: Callable[[Any, Any], Any]
798798
runtimeContext # type: RuntimeContext
799799
): # type: (...) -> Generator[Any, None, None]

cwltool/update.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import copy
44
import re
5-
from typing import Any, Callable, Dict, Optional, Tuple, Union, MutableMapping, MutableSequence
5+
from typing import (Any, Callable, Dict, Optional, Tuple, Union,
6+
MutableMapping, MutableSequence)
67
from typing_extensions import Text # pylint: disable=unused-import
78
# move to a regular typing import when Python 3.3-3.6 is no longer supported
89

@@ -15,7 +16,7 @@
1516
from .utils import visit_class
1617

1718

18-
def findId(doc, frg): # type: (Any, Any) -> Optional[Dict]
19+
def findId(doc, frg): # type: (Any, Any) -> Optional[MutableMapping]
1920
if isinstance(doc, MutableMapping):
2021
if "id" in doc and doc["id"] == frg:
2122
return doc
@@ -84,7 +85,7 @@ def traverseImport(doc, loader, baseuri, func):
8485
return doc["$import"]
8586
imp = urllib.parse.urljoin(baseuri, doc["$import"])
8687
impLoaded = loader.fetch(imp)
87-
r = {} # type: Dict[Text, Any]
88+
r = {} # type: MutableMapping[Text, Any]
8889
if isinstance(impLoaded, MutableSequence):
8990
r = {"$graph": impLoaded}
9091
elif isinstance(impLoaded, MutableMapping):

cwltool/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def versionstring():
4848
return u"%s %s" % (sys.argv[0], pkg[0].version)
4949
return u"%s %s" % (sys.argv[0], "unknown version")
5050

51-
def aslist(l): # type: (Any) -> List[Any]
51+
def aslist(l): # type: (Any) -> MutableSequence[Any]
5252
if isinstance(l, MutableSequence):
5353
return l
5454
return [l]
@@ -172,8 +172,8 @@ def cmp_like_py2(dict1, dict2): # type: (Dict[Text, Any], Dict[Text, Any]) -> i
172172
return 0
173173

174174

175-
def bytes2str_in_dicts(inp # type: Union[Dict[Text, Any], List[Any], Any]
176-
): # type: (...) -> Union[Text, List[Any], Dict[Text, Any]]
175+
def bytes2str_in_dicts(inp # type: Union[MutableMapping[Text, Any], MutableSequence[Any], Any]
176+
): # type: (...) -> Union[Text, MutableSequence[Any], MutableMapping[Text, Any]]
177177
"""
178178
Convert any present byte string to unicode string, inplace.
179179
input is a dict of nested dicts and lists

cwltool/workflow.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
WorkflowStateItem = namedtuple('WorkflowStateItem', ['parameter', 'value', 'success'])
4242

4343

44-
def default_make_tool(toolpath_object, # type: Dict[Text, Any]
44+
def default_make_tool(toolpath_object, # type: MutableMapping[Text, Any]
4545
loadingContext # type: LoadingContext
4646
): # type: (...) -> Process
4747
if not isinstance(toolpath_object, MutableMapping):
@@ -189,7 +189,7 @@ def __init__(self, step):
189189
self.parent_wf = step.parent_wf
190190

191191
def job(self,
192-
joborder, # type: Dict[Text, Text]
192+
joborder, # type: MutableMapping[Text, Text]
193193
output_callback, # type: functools.partial[None]
194194
runtimeContext # type: RuntimeContext
195195
):
@@ -337,7 +337,7 @@ def try_make_job(self,
337337
vfinputs = {shortname(k): v for k, v in six.iteritems(inputobj)}
338338

339339
def postScatterEval(io):
340-
# type: (Dict[Text, Any]) -> Dict[Text, Any]
340+
# type: (MutableMapping[Text, Any]) -> Dict[Text, Any]
341341
shortio = {shortname(k): v for k, v in six.iteritems(io)}
342342

343343
fs_access = getdefault(runtimeContext.make_fs_access, StdFsAccess)("")
@@ -415,7 +415,7 @@ def run(self, runtimeContext):
415415
_logger.info(u"[%s] start", self.name)
416416

417417
def job(self,
418-
joborder, # type: Dict[Text, Any]
418+
joborder, # type: MutableMapping[Text, Any]
419419
output_callback, # type: Callable[[Any, Any], Any]
420420
runtimeContext # type: RuntimeContext
421421
): # type: (...) -> Generator
@@ -495,7 +495,7 @@ def job(self,
495495

496496
class Workflow(Process):
497497
def __init__(self,
498-
toolpath_object, # type: Dict[Text, Any]
498+
toolpath_object, # type: MutableMapping[Text, Any]
499499
loadingContext # type: LoadingContext
500500
): # type: (...) -> None
501501
super(Workflow, self).__init__(
@@ -558,7 +558,7 @@ def __init__(self,
558558

559559

560560
def job(self,
561-
job_order, # type: Dict[Text, Text]
561+
job_order, # type: MutableMapping[Text, Text]
562562
output_callbacks, # type: Callable[[Any, Any], Any]
563563
runtimeContext # type: RuntimeContext
564564
): # type: (...) -> Generator[Any, None, None]
@@ -610,7 +610,8 @@ def __init__(self,
610610

611611
try:
612612
if isinstance(toolpath_object["run"], MutableMapping):
613-
self.embedded_tool = loadingContext.construct_tool_object(toolpath_object["run"], loadingContext)
613+
self.embedded_tool = loadingContext.construct_tool_object(
614+
toolpath_object["run"], loadingContext)
614615
else:
615616
self.embedded_tool = load_tool(
616617
toolpath_object["run"], loadingContext)
@@ -752,7 +753,7 @@ def receive_output(self, output_callback, jobout, processStatus):
752753
output_callback(output, processStatus)
753754

754755
def job(self,
755-
job_order, # type: Dict[Text, Text]
756+
job_order, # type: MutableMapping[Text, Text]
756757
output_callbacks, # type: Callable[[Any, Any], Any]
757758
runtimeContext, # type: RuntimeContext
758759
): # type: (...) -> Generator[Any, None, None]
@@ -845,8 +846,8 @@ def parallel_steps(steps, rc, runtimeContext):
845846

846847

847848
def dotproduct_scatter(process, # type: WorkflowJobStep
848-
joborder, # type: Dict[Text, Any]
849-
scatter_keys, # type: List[Text]
849+
joborder, # type: MutableMapping[Text, Any]
850+
scatter_keys, # type: MutableSequence[Text]
850851
output_callback, # type: Callable[..., Any]
851852
runtimeContext # type: RuntimeContext
852853
): # type: (...) -> Generator
@@ -884,8 +885,8 @@ def dotproduct_scatter(process, # type: WorkflowJobStep
884885

885886

886887
def nested_crossproduct_scatter(process, # type: WorkflowJobStep
887-
joborder, # type: Dict[Text, Any]
888-
scatter_keys, # type: List[Text]
888+
joborder, # type: MutableMapping[Text, Any]
889+
scatter_keys, # type: MutableSequence[Text]
889890
output_callback, # type: Callable[..., Any]
890891
runtimeContext # type: RuntimeContext
891892
): #type: (...) -> Generator
@@ -919,7 +920,7 @@ def nested_crossproduct_scatter(process, # type: WorkflowJobStep
919920

920921

921922
def crossproduct_size(joborder, scatter_keys):
922-
# type: (Dict[Text, Any], List[Text]) -> int
923+
# type: (MutableMapping[Text, Any], MutableSequence[Text]) -> int
923924
scatter_key = scatter_keys[0]
924925
if len(scatter_keys) == 1:
925926
ssum = len(joborder[scatter_key])
@@ -929,11 +930,11 @@ def crossproduct_size(joborder, scatter_keys):
929930
ssum += crossproduct_size(joborder, scatter_keys[1:])
930931
return ssum
931932

932-
def flat_crossproduct_scatter(process, # type: WorkflowJobStep
933-
joborder, # type: Dict[Text, Any]
934-
scatter_keys, # type: List[Text]
935-
output_callback, # type: Callable[..., Any]
936-
runtimeContext # type: RuntimeContext
933+
def flat_crossproduct_scatter(process, # type: WorkflowJobStep
934+
joborder, # type: MutableMapping[Text, Any]
935+
scatter_keys, # type: MutableSequence[Text]
936+
output_callback, # type: Callable[..., Any]
937+
runtimeContext # type: RuntimeContext
937938
): # type: (...) -> Generator
938939
output = {} # type: Dict[Text, List[Optional[Text]]]
939940
for i in process.tool["outputs"]:
@@ -944,12 +945,12 @@ def flat_crossproduct_scatter(process, # type: WorkflowJobStep
944945
callback.setTotal(total)
945946
return parallel_steps(steps, callback, runtimeContext)
946947

947-
def _flat_crossproduct_scatter(process, # type: WorkflowJobStep
948-
joborder, # type: Dict[Text, Any]
949-
scatter_keys, # type: List[Text]
950-
callback, # type: ReceiveScatterOutput
951-
startindex, # type: int
952-
runtimeContext # type: RuntimeContext
948+
def _flat_crossproduct_scatter(process, # type: WorkflowJobStep
949+
joborder, # type: MutableMapping[Text, Any]
950+
scatter_keys, # type: MutableSequence[Text]
951+
callback, # type: ReceiveScatterOutput
952+
startindex, # type: int
953+
runtimeContext # type: RuntimeContext
953954
): # type: (...) -> Tuple[List[Generator], int]
954955
""" Inner loop. """
955956
scatter_key = scatter_keys[0]

0 commit comments

Comments
 (0)