1010import sys
1111from copy import deepcopy
1212from pathlib import Path
13- from typing import Any , Dict , List , Optional , Union
13+ from typing import Any , Optional , Union
1414from urllib .parse import urlparse
1515
1616import requests
@@ -85,22 +85,22 @@ class JSONSchemaProperty:
8585 def __init__ (
8686 self ,
8787 name : str ,
88- type_ : Union [InputType , List [InputType ], str , Any ],
88+ type_ : Union [InputType , list [InputType ], str , Any ],
8989 description : Optional [str ] = "" ,
9090 required : Optional [bool ] = False ,
9191 ):
9292 """Initialise the JSONSchemaProperty object."""
9393 # Initialise values
9494 self .name : str = name
95- self .type_ : Union [InputType , List [InputType ], str , Any ] = type_
95+ self .type_ : Union [InputType , list [InputType ], str , Any ] = type_
9696 self .description = description
9797 self .required = required
9898 self .type_dict = self .generate_type_dict ()
9999
100- def generate_type_dict (self ) -> Dict [str , Any ]:
100+ def generate_type_dict (self ) -> dict [str , Any ]:
101101 """Generate the type dict for a property from a CWL input parameter type."""
102102 # If the type is a list and contains null, then the property is not required
103- if isinstance (self .type_ , List ) and "null" in self .type_ :
103+ if isinstance (self .type_ , list ) and "null" in self .type_ :
104104 self .required = False
105105 self .type_ = list (filter (lambda type_item : type_item != "null" , self .type_ ))
106106
@@ -109,7 +109,7 @@ def generate_type_dict(self) -> Dict[str, Any]:
109109 self .type_ = self .type_ [0 ]
110110
111111 # type_ is still a list therefore we offer multiple input types for this parameter
112- if isinstance (self .type_ , List ):
112+ if isinstance (self .type_ , list ):
113113 # We use the oneOf keyword to specify multiple types
114114 type_dict = self .generate_type_dict_from_type_list (self .type_ )
115115 # type_ is a single type
@@ -121,7 +121,7 @@ def generate_type_dict(self) -> Dict[str, Any]:
121121
122122 return type_dict
123123
124- def generate_type_dict_from_type (self , type_item : Any ) -> Dict [str , Any ]:
124+ def generate_type_dict_from_type (self , type_item : Any ) -> dict [str , Any ]:
125125 """
126126 Generate the type dict for a property from a CWL input parameter type.
127127
@@ -162,7 +162,7 @@ def generate_type_dict_from_type(self, type_item: Any) -> Dict[str, Any]:
162162 elif isinstance (type_item , InputRecordSchemaTypes ):
163163 if type_item .fields is None :
164164 return {"type" : "object" }
165- if not isinstance (type_item .fields , List ):
165+ if not isinstance (type_item .fields , list ):
166166 _cwlutilslogger .error (
167167 "Expected fields of InputRecordSchemaType to be a list"
168168 )
@@ -176,7 +176,7 @@ def generate_type_dict_from_type(self, type_item: Any) -> Dict[str, Any]:
176176 for prop in type_item .fields
177177 },
178178 }
179- elif isinstance (type_item , Dict ):
179+ elif isinstance (type_item , dict ):
180180 # Nested import
181181 # {'$import': '../relative/path/to/schema'}
182182 if "$import" in type_item .keys ():
@@ -186,7 +186,7 @@ def generate_type_dict_from_type(self, type_item: Any) -> Dict[str, Any]:
186186 }
187187 else :
188188 raise ValueError (f"Unknown type: { type_item } " )
189- elif isinstance (type_item , List ):
189+ elif isinstance (type_item , list ):
190190 # Nested schema
191191 return {
192192 "oneOf" : list (
@@ -200,8 +200,8 @@ def generate_type_dict_from_type(self, type_item: Any) -> Dict[str, Any]:
200200 raise ValueError (f"Unknown type: { type_item } " )
201201
202202 def generate_type_dict_from_type_list (
203- self , type_ : List [InputType ]
204- ) -> Dict [str , Any ]:
203+ self , type_ : list [InputType ]
204+ ) -> dict [str , Any ]:
205205 """Given a list of types, generate a JSON schema property dict wrapped in oneOf list."""
206206 return {
207207 "oneOf" : list (
@@ -212,7 +212,7 @@ def generate_type_dict_from_type_list(
212212 )
213213 }
214214
215- def to_dict (self ) -> Dict [str , Any ]:
215+ def to_dict (self ) -> dict [str , Any ]:
216216 """Return as a dictionary."""
217217 return {self .name : self .type_dict }
218218
@@ -225,7 +225,7 @@ def get_is_required_from_input_parameter(
225225 return False
226226 if input_parameter .default is not None :
227227 return False
228- if isinstance (input_parameter .type_ , List ) and "null" in input_parameter .type_ :
228+ if isinstance (input_parameter .type_ , list ) and "null" in input_parameter .type_ :
229229 return False
230230 if isinstance (input_parameter .type_ , InputRecordSchemaTypes ):
231231 if input_parameter .type_ is not None :
@@ -258,7 +258,7 @@ def generate_json_schema_property_from_input_parameter(
258258 )
259259
260260
261- def generate_definition_from_schema (schema : InputRecordSchema ) -> Dict [str , Any ]:
261+ def generate_definition_from_schema (schema : InputRecordSchema ) -> dict [str , Any ]:
262262 """
263263 Given a schema, generate a JSON schema definition.
264264
@@ -291,7 +291,7 @@ def generate_definition_from_schema(schema: InputRecordSchema) -> Dict[str, Any]
291291 if isinstance (prop_obj , str ):
292292 raise TypeError ("Property Object should be a dictionary" )
293293
294- if isinstance (prop_obj .get ("type" , []), List ):
294+ if isinstance (prop_obj .get ("type" , []), list ):
295295 if "null" in prop_obj .get ("type" , []):
296296 required = False
297297 prop_obj ["type" ] = list (
@@ -333,7 +333,7 @@ def cwl_to_jsonschema(cwl_obj: Union[Workflow, CommandLineTool]) -> Any:
333333
334334 """
335335 # Initialise the schema from the workflow input json schema template
336- with open (JSON_TEMPLATE_PATH , "r" ) as template_h :
336+ with open (JSON_TEMPLATE_PATH ) as template_h :
337337 input_json_schema = json .load (template_h )
338338
339339 # Get the complex schema keys
@@ -354,7 +354,7 @@ def is_complex_record_schema_key(idx_iter: str) -> TypeGuard[bool]:
354354 return True
355355 return False
356356
357- complex_schema_keys : List [str ] = list (
357+ complex_schema_keys : list [str ] = list (
358358 filter (
359359 lambda idx_iter : is_complex_record_schema_key (idx_iter ),
360360 cwl_obj .loadingOptions .idx .keys (),
@@ -376,7 +376,7 @@ def get_complex_schema_values(idx_iter: str) -> InputRecordSchema:
376376
377377 return input_record_schema
378378
379- complex_schema_values : List [InputRecordSchema ] = list (
379+ complex_schema_values : list [InputRecordSchema ] = list (
380380 map (
381381 lambda idx_iter : get_complex_schema_values (idx_iter ),
382382 complex_schema_keys ,
@@ -462,9 +462,9 @@ def get_complex_schema_values(idx_iter: str) -> InputRecordSchema:
462462
463463# Traverse the properties and return all definitions that are used
464464def _recursive_search (
465- json_data : Dict [str , Any ],
465+ json_data : dict [str , Any ],
466466 target_key : str ,
467- ) -> List [Any ]:
467+ ) -> list [Any ]:
468468 """Given a target key return all instances of a key in a json object."""
469469 result = []
470470
@@ -482,16 +482,16 @@ def _recursive_search(
482482
483483
484484# Get all the property dependencies
485- def _get_all_ref_attributes (json_object : Dict [str , Any ]) -> List [Any ]:
485+ def _get_all_ref_attributes (json_object : dict [str , Any ]) -> list [Any ]:
486486 """Given a json object, return all the reference attributes."""
487487 return _recursive_search (json_object , "$ref" )
488488
489489
490490def get_property_dependencies (
491- property_dict : Dict [str , Any ],
492- input_json_schema : Dict [str , Any ],
493- existing_property_dependencies : Optional [List [Any ]] = None ,
494- ) -> List [str ]:
491+ property_dict : dict [str , Any ],
492+ input_json_schema : dict [str , Any ],
493+ existing_property_dependencies : Optional [list [Any ]] = None ,
494+ ) -> list [str ]:
495495 """Recursively collect all dependencies for a property."""
496496 # Initialise return list
497497 if existing_property_dependencies is None :
@@ -516,7 +516,7 @@ def get_property_dependencies(
516516 return existing_property_dependencies
517517
518518
519- def slim_definitions (input_json_schema : Dict [str , Any ]) -> Dict [str , Any ]:
519+ def slim_definitions (input_json_schema : dict [str , Any ]) -> dict [str , Any ]:
520520 """
521521 Slim down the schema to only the definitions that are used by the properties.
522522
@@ -552,7 +552,7 @@ def arg_parser() -> argparse.ArgumentParser:
552552 return parser
553553
554554
555- def parse_args (args : List [str ]) -> argparse .Namespace :
555+ def parse_args (args : list [str ]) -> argparse .Namespace :
556556 """Parse the command line arguments."""
557557 return arg_parser ().parse_args (args )
558558
0 commit comments