Skip to content

Commit 932464d

Browse files
committed
expression.py: type annotations improvements
1 parent cbd20ab commit 932464d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cwltool/expression.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import re
77
from typing import Any, AnyStr, Dict, List, Text, Union
8+
import six
89
from six import u
910

1011
from . import sandboxjs
@@ -21,21 +22,21 @@ def jshead(engineConfig, rootvars):
2122
# to str in `rootvars` dict.
2223
# TODO: need to make sure the `rootvars dict`
2324
# contains no bytes type in the first place.
24-
rootvars = bytes2str_in_dicts(rootvars)
25+
if six.PY3:
26+
rootvars = bytes2str_in_dicts(rootvars) # type -> ignore
2527

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

2830

29-
# all these raw strings are decoded to unicode
30-
# object due to the __future__ import
31+
# decode all raw strings to unicode
3132
seg_symbol = r"""\w+"""
3233
seg_single = r"""\['([^']|\\')+'\]"""
3334
seg_double = r"""\["([^"]|\\")+"\]"""
3435
seg_index = r"""\[[0-9]+\]"""
3536
segments = r"(\.%s|%s|%s|%s)" % (seg_symbol, seg_single, seg_double, seg_index)
36-
segment_re = re.compile(segments, flags=re.UNICODE)
37+
segment_re = re.compile(u(segments), flags=re.UNICODE)
3738
param_str = r"\((%s)%s*\)$" % (seg_symbol, segments)
38-
param_re = re.compile(param_str, flags=re.UNICODE)
39+
param_re = re.compile(u(param_str), flags=re.UNICODE)
3940

4041
JSON = Union[Dict[Any, Any], List[Any], Text, int, float, bool, None]
4142

@@ -119,7 +120,7 @@ def scanner(scan): # type: (Text) -> List[int]
119120
return None
120121

121122

122-
def next_seg(remain, obj): # type: (str, Any) -> Any
123+
def next_seg(remain, obj): # type: (Text, Any) -> Any
123124
if remain:
124125
m = segment_re.match(remain)
125126
key = None # type: Union[Text, int]
@@ -153,7 +154,7 @@ def next_seg(remain, obj): # type: (str, Any) -> Any
153154

154155

155156
def evaluator(ex, jslib, obj, fullJS=False, timeout=None, debug=False):
156-
# type: (str, Text, Dict[Text, Any], bool, int, bool) -> JSON
157+
# type: (Text, Text, Dict[Text, Any], bool, int, bool) -> JSON
157158
m = param_re.match(ex)
158159
if m:
159160
if m.end(1)+1 == len(ex) and m.group(1) == "null":

0 commit comments

Comments
 (0)