33from collections .abc import Iterator , MutableMapping , MutableSequence , Sized
44from typing import Any , Literal , NamedTuple , Optional , Union , cast
55
6- from cwl_utils .types import CWLObjectType , CWLOutputType
6+ from cwl_utils .types import CWLObjectType , CWLOutputType , SinkType
77from schema_salad .exceptions import ValidationException
88from schema_salad .sourceline import SourceLine , bullets , strip_dup_lineno
99from schema_salad .utils import json_dumps
1010
1111from .errors import WorkflowException
1212from .loghandler import _logger
1313from .process import shortname
14- from .utils import SinkType , aslist
14+ from .utils import aslist
1515
1616
1717def _get_type (tp : Any ) -> Any :
@@ -22,8 +22,8 @@ def _get_type(tp: Any) -> Any:
2222
2323
2424def check_types (
25- srctype : SinkType ,
26- sinktype : SinkType ,
25+ srctype : SinkType | None ,
26+ sinktype : SinkType | None ,
2727 linkMerge : str | None ,
2828 pickValue : str | None ,
2929 valueFrom : str | None ,
@@ -83,18 +83,20 @@ def check_types(
8383 raise WorkflowException (f"Unrecognized linkMerge enum { linkMerge !r} " )
8484
8585
86- def merge_flatten_type (src : SinkType ) -> CWLOutputType :
86+ def merge_flatten_type (src : SinkType | None ) -> CWLOutputType | None :
8787 """Return the merge flattened type of the source type."""
8888 match src :
8989 case MutableSequence ():
90- return [merge_flatten_type (cast ( SinkType , t ) ) for t in src ]
90+ return [merge_flatten_type (t ) for t in src ]
9191 case {"type" : "array" }:
9292 return src
9393 case _:
9494 return {"items" : src , "type" : "array" }
9595
9696
97- def can_assign_src_to_sink (src : SinkType , sink : SinkType | None , strict : bool = False ) -> bool :
97+ def can_assign_src_to_sink (
98+ src : SinkType | None , sink : SinkType | None , strict : bool = False
99+ ) -> bool :
98100 """
99101 Check for identical type specifications, ignoring extra keys like inputBinding.
100102
@@ -112,8 +114,8 @@ def can_assign_src_to_sink(src: SinkType, sink: SinkType | None, strict: bool =
112114 return False
113115 if src ["type" ] == "array" and sink ["type" ] == "array" :
114116 return can_assign_src_to_sink (
115- cast (SinkType , src ["items" ]),
116- cast (SinkType , sink ["items" ]),
117+ cast (MutableSequence [ CWLOutputType | None ] , src ["items" ]),
118+ cast (MutableSequence [ CWLOutputType | None ] , sink ["items" ]),
117119 strict ,
118120 )
119121 if src ["type" ] == "record" and sink ["type" ] == "record" :
@@ -128,15 +130,15 @@ def can_assign_src_to_sink(src: SinkType, sink: SinkType | None, strict: bool =
128130 if strict :
129131 return False
130132 return True
131- return can_assign_src_to_sink (cast ( SinkType , src ["type" ]) , sink ["type" ], strict )
133+ return can_assign_src_to_sink (src ["type" ], sink ["type" ], strict )
132134 if isinstance (src , MutableSequence ):
133135 if strict :
134136 for this_src in src :
135- if not can_assign_src_to_sink (cast ( SinkType , this_src ) , sink ):
137+ if not can_assign_src_to_sink (this_src , sink ):
136138 return False
137139 return True
138140 for this_src in src :
139- if this_src != "null" and can_assign_src_to_sink (cast ( SinkType , this_src ) , sink ):
141+ if this_src != "null" and can_assign_src_to_sink (this_src , sink ):
140142 return True
141143 return False
142144 if isinstance (sink , MutableSequence ):
0 commit comments