22import copy
33import logging
44import math
5- from typing import (
5+ from typing import ( # pylint: disable=unused-import
66 IO ,
7+ TYPE_CHECKING ,
78 Any ,
89 Callable ,
910 Dict ,
1011 List ,
1112 MutableMapping ,
1213 MutableSequence ,
1314 Optional ,
15+ Type ,
1416 Union ,
1517 cast ,
1618)
1719
1820from cwl_utils import expression
1921from cwl_utils .file_formats import check_format
2022from rdflib import Graph
21- from ruamel .yaml .comments import CommentedMap
2223from schema_salad .avro .schema import Names , Schema , make_avsc_object
2324from schema_salad .exceptions import ValidationException
2425from schema_salad .sourceline import SourceLine
2526from schema_salad .utils import convert_to_dict , json_dumps
2627from schema_salad .validate import validate
27- from typing_extensions import TYPE_CHECKING , Type # pylint: disable=unused-import
28+
29+ from ruamel .yaml .comments import CommentedMap
2830
2931from .errors import WorkflowException
3032from .loghandler import _logger
@@ -186,10 +188,8 @@ def bind_input(
186188 if lead_pos is None :
187189 lead_pos = []
188190
189- bindings = [] # type: List[MutableMapping[str, Union[str, List[int]]]]
190- binding = (
191- {}
192- ) # type: Union[MutableMapping[str, Union[str, List[int]]], CommentedMap]
191+ bindings : List [MutableMapping [str , Union [str , List [int ]]]] = []
192+ binding : Union [MutableMapping [str , Union [str , List [int ]]], CommentedMap ] = {}
193193 value_from_expression = False
194194 if "inputBinding" in schema and isinstance (
195195 schema ["inputBinding" ], MutableMapping
@@ -208,7 +208,7 @@ def bind_input(
208208 ).makeError (
209209 "'position' expressions must evaluate to an int, "
210210 f"not a { type (result )} . Expression { position } "
211- f"resulted in ' { result } ' ."
211+ f"resulted in { result !r } ."
212212 )
213213 binding ["position" ] = result
214214 bp .append (result )
@@ -227,7 +227,7 @@ def bind_input(
227227 if isinstance (schema ["type" ], MutableSequence ):
228228 bound_input = False
229229 for t in schema ["type" ]:
230- avsc = None # type : Optional[Schema]
230+ avsc : Optional [Schema ] = None
231231 if isinstance (t , str ) and self .names .has_name (t , None ):
232232 avsc = self .names .get_name (t , None )
233233 elif (
@@ -336,10 +336,10 @@ def bind_input(
336336 if binding :
337337 b2 = cast (CWLObjectType , copy .deepcopy (binding ))
338338 b2 ["datum" ] = item
339- itemschema = {
339+ itemschema : CWLObjectType = {
340340 "type" : schema ["items" ],
341341 "inputBinding" : b2 ,
342- } # type: CWLObjectType
342+ }
343343 for k in ("secondaryFiles" , "format" , "streamable" ):
344344 if k in schema :
345345 itemschema [k ] = schema [k ]
@@ -362,9 +362,9 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
362362 datum = cast (CWLObjectType , datum )
363363 self .files .append (datum )
364364
365- loadContents_sourceline = (
366- None
367- ) # type: Union[ None, MutableMapping[str, Union[str, List[int]]], CWLObjectType]
365+ loadContents_sourceline : Union [
366+ None , MutableMapping [ str , Union [ str , List [ int ]]], CWLObjectType
367+ ] = None
368368 if binding and binding .get ("loadContents" ):
369369 loadContents_sourceline = binding
370370 elif schema .get ("loadContents" ):
@@ -385,7 +385,7 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
385385 except Exception as e :
386386 raise Exception (
387387 "Reading {}\n {}" .format (datum ["location" ], e )
388- )
388+ ) from e
389389
390390 if "secondaryFiles" in schema :
391391 if "secondaryFiles" not in datum :
@@ -415,8 +415,8 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
415415 "The result of a expression in the field "
416416 "'required' must "
417417 f"be a bool or None, not a { type (required_result )} . "
418- f"Expression ' { sf_entry ['required' ]} ' resulted "
419- f"in ' { required_result } ' ."
418+ f"Expression { sf_entry ['required' ]!r } resulted "
419+ f"in { required_result !r } ."
420420 )
421421 sf_required = required_result
422422 else :
@@ -454,7 +454,7 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
454454 "Expected secondaryFile expression to "
455455 "return type 'str', a 'File' or 'Directory' "
456456 "dictionary, or a list of the same. Received "
457- f"' { type (sfname )} from ' { sf_entry ['pattern' ]} ' ."
457+ f"{ type (sfname )!r } from { sf_entry ['pattern' ]!r } ."
458458 )
459459
460460 for d in cast (
@@ -529,9 +529,9 @@ def addsf(
529529 "An expression in the 'format' field must "
530530 "evaluate to a string, or list of strings. "
531531 "However a non-string item was received: "
532- f"' { entry } ' of type ' { type (entry )} ' . "
533- f"The expression was ' { schema ['format' ]} ' and "
534- f"its fully evaluated result is ' { eval_format } ' ."
532+ f"{ entry !r } of type { type (entry )!r } . "
533+ f"The expression was { schema ['format' ]!r } and "
534+ f"its fully evaluated result is { eval_format !r } ."
535535 )
536536 if expression .needs_parsing (entry ):
537537 message = (
@@ -542,7 +542,7 @@ def addsf(
542542 "Expressions or CWL Parameter References. List "
543543 f"entry number { index + 1 } contains the following "
544544 "unallowed CWL Parameter Reference or Expression: "
545- f"' { entry } ' ."
545+ f"{ entry !r } ."
546546 )
547547 if message :
548548 raise SourceLine (
@@ -557,8 +557,8 @@ def addsf(
557557 "evaluate to a string, or list of strings. "
558558 "However the type of the expression result was "
559559 f"{ type (eval_format )} . "
560- f"The expression was ' { schema ['format' ]} ' and "
561- f"its fully evaluated result is ' eval_format' ."
560+ f"The expression was { schema ['format' ]!r } and "
561+ f"its fully evaluated result is { eval_format !r } ."
562562 )
563563 try :
564564 check_format (
@@ -568,8 +568,8 @@ def addsf(
568568 )
569569 except ValidationException as ve :
570570 raise WorkflowException (
571- "Expected value of '%s' to have format %s but \n "
572- " %s" % ( schema ["name" ], schema [ " format" ], ve )
571+ f "Expected value of { schema [ 'name' ]!r } to have "
572+ f"format { schema [' format' ]!r } but \n { ve } "
573573 ) from ve
574574
575575 visit_class (
@@ -646,7 +646,7 @@ def generate_arg(self, binding: CWLObjectType) -> List[str]:
646646 "'separate' option can not be specified without prefix"
647647 )
648648
649- argl = [] # type: MutableSequence[CWLOutputType ]
649+ argl : MutableSequence [ CWLOutputType ] = [ ]
650650 if isinstance (value , MutableSequence ):
651651 if binding .get ("itemSeparator" ) and value :
652652 itemSeparator = cast (str , binding ["itemSeparator" ])
0 commit comments