Skip to content

Commit 342bbea

Browse files
committed
type workaround
1 parent a1cc60c commit 342bbea

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

cwl_utils/expression.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
from collections.abc import Awaitable, MutableMapping
88
from enum import Enum
9-
from typing import Any, Union, cast
9+
from typing import Any, Literal, Union, cast
1010

1111
from schema_salad.utils import json_dumps
1212

@@ -123,31 +123,35 @@ def evaluator(
123123
if first_symbol_end + 1 == len(ex) and first_symbol == "null":
124124
return None
125125
try:
126-
if first_symbol not in obj:
127-
raise WorkflowException("%s is not defined" % first_symbol)
128-
129-
if inspect.iscoroutinefunction(js_engine.regex_eval):
130-
return asyncio.get_event_loop().run_until_complete(
131-
cast(
132-
Awaitable[CWLOutputType],
126+
if first_symbol in ("inputs", "self", "runtime"):
127+
symbol = cast(
128+
Literal["inputs"] | Literal["self"] | Literal["runtime"],
129+
first_symbol,
130+
)
131+
if inspect.iscoroutinefunction(js_engine.regex_eval):
132+
return asyncio.get_event_loop().run_until_complete(
133+
cast(
134+
Awaitable[CWLOutputType],
135+
js_engine.regex_eval(
136+
first_symbol,
137+
ex[first_symbol_end:-1],
138+
cast(CWLOutputType, obj[symbol]),
139+
**kwargs,
140+
),
141+
)
142+
)
143+
else:
144+
return cast(
145+
CWLOutputType,
133146
js_engine.regex_eval(
134147
first_symbol,
135148
ex[first_symbol_end:-1],
136-
cast(CWLOutputType, obj[first_symbol]), # type: ignore[literal-required]
149+
cast(CWLOutputType, obj[symbol]),
137150
**kwargs,
138151
),
139152
)
140-
)
141153
else:
142-
return cast(
143-
CWLOutputType,
144-
js_engine.regex_eval(
145-
first_symbol,
146-
ex[first_symbol_end:-1],
147-
cast(CWLOutputType, obj[first_symbol]), # type: ignore[literal-required]
148-
**kwargs,
149-
),
150-
)
154+
raise WorkflowException(f"{first_symbol} is unexpected.")
151155
except WorkflowException as werr:
152156
expression_parse_exception = werr
153157
if fullJS:

cwl_utils/parser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from schema_salad.exceptions import ValidationException
1111
from schema_salad.utils import yaml_no_ts
1212

13-
from . import cwl_v1_0, cwl_v1_1, cwl_v1_2
1413
from ..errors import GraphTargetMissingException
14+
from . import cwl_v1_0, cwl_v1_1, cwl_v1_2
1515

1616

1717
class NoType(ABC):

0 commit comments

Comments
 (0)