Skip to content

Commit a431179

Browse files
committed
cwltool: misc annotation improvements to fix mypy failing tests
includes few ignore types which I plan to remove in the future iteration
1 parent 86c3e40 commit a431179

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

cwltool/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def __init__(self): # type: () -> None
6060
self.job_script_provider = None # type: Any
6161

6262
def build_job_script(self, commands):
63-
# type: (List[str]) -> Text
64-
build_job_script_method = getattr(self.job_script_provider, "build_job_script", None) # type: Callable[[Builder, List[str]], Text]
63+
# type: (List[bytes]) -> Text
64+
build_job_script_method = getattr(self.job_script_provider, "build_job_script", None) # type: Callable[[Builder, List[bytes]], Text]
6565
if build_job_script_method:
6666
return build_job_script_method(self, commands)
6767
else:

cwltool/expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def jshead(engineConfig, rootvars):
2222
# TODO: need to make sure the `rootvars dict`
2323
# contains no bytes type in the first place.
2424
if six.PY3:
25-
rootvars = bytes2str_in_dicts(rootvars) # type -> ignore
25+
rootvars = bytes2str_in_dicts(rootvars) # type: ignore
2626

2727
return u"\n".join(engineConfig + [u"var %s = %s;" % (k, json.dumps(v, indent=4)) for k, v in rootvars.items()])
2828

cwltool/job.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .pathmapper import PathMapper
2424
from .process import (UnsupportedRequirement, empty_subtree, get_feature,
2525
stageFiles)
26+
from .utils import bytes2str_in_dicts
2627

2728
_logger = logging.getLogger("cwltool")
2829

@@ -223,6 +224,7 @@ def _execute(self, runtime, env, rm_tmpdir=True, move_outputs="move"):
223224
relink_initialworkdir(self.generatemapper, inplace_update=self.inplace_update)
224225

225226
outputs = self.collect_outputs(self.outdir)
227+
outputs = bytes2str_in_dicts(outputs) # type: ignore
226228

227229
except OSError as e:
228230
if e.errno == 2:
@@ -401,7 +403,7 @@ def run(self, pull_image=True, rm_container=True,
401403

402404

403405
def _job_popen(
404-
commands, # type: List[str]
406+
commands, # type: List[bytes]
405407
stdin_path, # type: Text
406408
stdout_path, # type: Text
407409
stderr_path, # type: Text
@@ -464,9 +466,8 @@ def _job_popen(
464466
job_script_contents = SHELL_COMMAND_TEMPLATE
465467

466468
env_copy = {}
467-
key = None # type: Union[Text, bytes]
469+
key = None # type: Any
468470
for key in env:
469-
key = key.encode("utf-8")
470471
env_copy[key] = env[key]
471472

472473
job_description = dict(

cwltool/load_tool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def fetch_document(argsworkflow, # type: Union[Text, Dict[Text, Any]]
4141
# type: (...) -> Tuple[Loader, CommentedMap, Text]
4242
"""Retrieve a CWL document."""
4343

44-
document_loader = Loader(jobloaderctx,
45-
fetcher_constructor=fetcher_constructor)
44+
document_loader = Loader(jobloaderctx, fetcher_constructor=fetcher_constructor) # type: ignore
4645

4746
uri = None # type: Text
4847
workflowobj = None # type: CommentedMap

cwltool/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def load_job_order(args, t, stdin, print_input_deps=False, relative_deps=False,
448448

449449
_jobloaderctx = jobloaderctx.copy()
450450
_jobloaderctx.update(t.metadata.get("$namespaces", {}))
451-
loader = Loader(_jobloaderctx, fetcher_constructor=fetcher_constructor)
451+
loader = Loader(_jobloaderctx, fetcher_constructor=fetcher_constructor) # type: ignore
452452

453453
if len(args.job_order) == 1 and args.job_order[0][0] != "-":
454454
job_order_file = args.job_order[0]

cwltool/stdfsaccess.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import
22
import glob
33
import os
4-
from typing import BinaryIO, List, Text, IO
4+
from typing import BinaryIO, List, Union, Text, IO, overload
55

66
import six
77
from six.moves import urllib
@@ -24,7 +24,17 @@ def _abs(self, p): # type: (Text) -> Text
2424
def glob(self, pattern): # type: (Text) -> List[Text]
2525
return [file_uri(str(self._abs(l))) for l in glob.glob(self._abs(pattern))]
2626

27-
def open(self, fn, mode): # type: (Text, str) -> IO[bytes]
27+
# overload is related to mypy type checking and in no way
28+
# modifies the behaviour of the function.
29+
@overload
30+
def open(self, fn, mode='rb'): # type: (Text, str) -> IO[bytes]
31+
pass
32+
33+
@overload
34+
def open(self, fn, mode='r'): # type: (Text, str) -> IO[str]
35+
pass
36+
37+
def open(self, fn, mode):
2838
return open(self._abs(fn), mode)
2939

3040
def exists(self, fn): # type: (Text) -> bool

0 commit comments

Comments
 (0)