33import copy
44import logging
55import math
6- from collections .abc import MutableMapping , MutableSequence
6+ from collections .abc import Callable , MutableMapping , MutableSequence
77from decimal import Decimal
8- from typing import IO , TYPE_CHECKING , Any , Callable , Optional , Union , cast
8+ from typing import IO , TYPE_CHECKING , Any , Optional , cast
99
1010from cwl_utils import expression
1111from cwl_utils .file_formats import check_format
@@ -101,9 +101,9 @@ def __init__(
101101 names : Names ,
102102 requirements : list [CWLObjectType ],
103103 hints : list [CWLObjectType ],
104- resources : dict [str , Union [ int , float ] ],
105- mutation_manager : Optional [ MutationManager ] ,
106- formatgraph : Optional [ Graph ] ,
104+ resources : dict [str , int | float ],
105+ mutation_manager : MutationManager | None ,
106+ formatgraph : Graph | None ,
107107 make_fs_access : type [StdFsAccess ],
108108 fs_access : StdFsAccess ,
109109 job_script_provider : Optional ["DependenciesConfiguration" ],
@@ -157,10 +157,10 @@ def __init__(
157157
158158 self .pathmapper : Optional ["PathMapper" ] = None
159159 self .prov_obj : Optional ["ProvenanceProfile" ] = None
160- self .find_default_container : Optional [ Callable [[], str ]] = None
160+ self .find_default_container : Callable [[], str ] | None = None
161161 self .container_engine = container_engine
162162
163- def build_job_script (self , commands : list [str ]) -> Optional [ str ] :
163+ def build_job_script (self , commands : list [str ]) -> str | None :
164164 """Use the job_script_provider to turn the commands into a job script."""
165165 if self .job_script_provider is not None :
166166 return self .job_script_provider .build_job_script (self , commands )
@@ -169,11 +169,11 @@ def build_job_script(self, commands: list[str]) -> Optional[str]:
169169 def bind_input (
170170 self ,
171171 schema : CWLObjectType ,
172- datum : Union [ CWLObjectType , list [CWLObjectType ] ],
172+ datum : CWLObjectType | list [CWLObjectType ],
173173 discover_secondaryFiles : bool ,
174- lead_pos : Optional [ Union [ int , list [int ]]] = None ,
175- tail_pos : Optional [ Union [ str , list [int ]]] = None ,
176- ) -> list [MutableMapping [str , Union [ str , list [int ] ]]]:
174+ lead_pos : int | list [int ] | None = None ,
175+ tail_pos : str | list [int ] | None = None ,
176+ ) -> list [MutableMapping [str , str | list [int ]]]:
177177 """
178178 Bind an input object to the command line.
179179
@@ -189,8 +189,8 @@ def bind_input(
189189 if lead_pos is None :
190190 lead_pos = []
191191
192- bindings : list [MutableMapping [str , Union [ str , list [int ] ]]] = []
193- binding : Union [ MutableMapping [str , Union [ str , list [int ]]], CommentedMap ] = {}
192+ bindings : list [MutableMapping [str , str | list [int ]]] = []
193+ binding : MutableMapping [str , str | list [int ]] | CommentedMap = {}
194194 value_from_expression = False
195195 if "inputBinding" in schema and isinstance (schema ["inputBinding" ], MutableMapping ):
196196 binding = CommentedMap (schema ["inputBinding" ].items ())
@@ -226,7 +226,7 @@ def bind_input(
226226 if isinstance (schema ["type" ], MutableSequence ):
227227 bound_input = False
228228 for t in schema ["type" ]:
229- avsc : Optional [ Schema ] = None
229+ avsc : Schema | None = None
230230 if isinstance (t , str ) and self .names .has_name (t , None ):
231231 avsc = self .names .get_name (t , None )
232232 elif (
@@ -360,9 +360,9 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
360360 datum = cast (CWLObjectType , datum )
361361 self .files .append (datum )
362362
363- loadContents_sourceline : Union [
364- None , MutableMapping [str , Union [ str , list [int ]]], CWLObjectType
365- ] = None
363+ loadContents_sourceline : (
364+ None | MutableMapping [str , str | list [int ]] | CWLObjectType
365+ ) = None
366366 if binding and binding .get ("loadContents" ):
367367 loadContents_sourceline = binding
368368 elif schema .get ("loadContents" ):
@@ -502,7 +502,7 @@ def addsf(
502502 if "format" in schema :
503503 eval_format : Any = self .do_eval (schema ["format" ])
504504 if isinstance (eval_format , str ):
505- evaluated_format : Union [ str , list [str ] ] = eval_format
505+ evaluated_format : str | list [str ] = eval_format
506506 elif isinstance (eval_format , MutableSequence ):
507507 for index , entry in enumerate (eval_format ):
508508 message = None
@@ -582,7 +582,7 @@ def addsf(
582582
583583 return bindings
584584
585- def tostr (self , value : Union [ MutableMapping [str , str ], Any ] ) -> str :
585+ def tostr (self , value : MutableMapping [str , str ] | Any ) -> str :
586586 """
587587 Represent an input parameter as a string.
588588
@@ -668,11 +668,11 @@ def generate_arg(self, binding: CWLObjectType) -> list[str]:
668668
669669 def do_eval (
670670 self ,
671- ex : Optional [ CWLOutputType ] ,
672- context : Optional [ Any ] = None ,
671+ ex : CWLOutputType | None ,
672+ context : Any | None = None ,
673673 recursive : bool = False ,
674674 strip_whitespace : bool = True ,
675- ) -> Optional [ CWLOutputType ] :
675+ ) -> CWLOutputType | None :
676676 if recursive :
677677 if isinstance (ex , MutableMapping ):
678678 return {k : self .do_eval (v , context , recursive ) for k , v in ex .items ()}
0 commit comments