Skip to content

Commit 4bb5e47

Browse files
committed
tighten types
1 parent 512b667 commit 4bb5e47

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cwltool/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ def generate_parser(toolparser, tool, namemap, records):
444444
return toolparser
445445

446446
def generate_example_input(inptype):
447+
# type: (Union[Text, Dict[Text, Any]]) -> Any
447448
defaults = { 'null': 'null',
448449
'Any': 'null',
449450
'boolean': False,
@@ -458,7 +459,7 @@ def generate_example_input(inptype):
458459
'path': 'default/directory/path' } }
459460
if (not isinstance(inptype, str) and
460461
not isinstance(inptype, collections.Mapping)
461-
and isinstance(inptype, collections.Iterable)):
462+
and isinstance(inptype, collections.MutableSet)):
462463
if len(inptype) == 2 and 'null' in inptype:
463464
inptype.remove('null')
464465
return generate_example_input(inptype[0])
@@ -467,7 +468,7 @@ def generate_example_input(inptype):
467468
raise Exception("multi-types other than optional not yet supported"
468469
" for generating example input objects: %s"
469470
% inptype)
470-
if 'type' in inptype:
471+
if isinstance(inptype, collections.Mapping) and 'type' in inptype:
471472
if inptype['type'] == 'array':
472473
return [ generate_example_input(inptype['items']) ]
473474
elif inptype['type'] == 'enum':
@@ -476,9 +477,10 @@ def generate_example_input(inptype):
476477
elif inptype['type'] == 'record':
477478
record = {}
478479
for field in inptype['fields']:
479-
record[shortname(field)] = generate_example_input(field)
480+
record[shortname(field['name'])] = generate_example_input(
481+
field['type'])
480482
return record
481-
else:
483+
elif isinstance(inptype, str):
482484
return defaults.get(inptype, 'custom_type')
483485
# TODO: support custom types, complex arrays
484486

0 commit comments

Comments
 (0)