48
48
text ,
49
49
)
50
50
51
+ DOC_TYPE_MAP = {str : "String" , bool : "Boolean" , list : "Multiple" , int : "Integer" , float : "Float" }
52
+
53
+
54
+ def _doc (kind ):
55
+ return DOC_TYPE_MAP .get (kind , kind .__doc__ )
56
+
51
57
52
58
def asyncio_call (function , * args , ** kwargs ):
53
59
loop = asyncio .get_event_loop ()
@@ -227,7 +233,7 @@ def __init__(self, route, function):
227
233
self .output_doc = self .transform .__doc__
228
234
elif self .transform or self .interface .transform :
229
235
output_doc = self .transform or self .interface .transform
230
- self .output_doc = output_doc if type (output_doc ) is str else output_doc . __doc__
236
+ self .output_doc = output_doc if type (output_doc ) is str else _doc ( output_doc )
231
237
232
238
self .raise_on_invalid = route .get ("raise_on_invalid" , False )
233
239
if "on_invalid" in route :
@@ -310,7 +316,7 @@ def documentation(self, add_to=None):
310
316
for requirement in self .requires
311
317
]
312
318
doc ["outputs" ] = OrderedDict ()
313
- doc ["outputs" ]["format" ] = self .outputs . __doc__
319
+ doc ["outputs" ]["format" ] = _doc ( self .outputs )
314
320
doc ["outputs" ]["content_type" ] = self .outputs .content_type
315
321
parameters = [
316
322
param
@@ -329,7 +335,7 @@ def documentation(self, add_to=None):
329
335
continue
330
336
331
337
input_definition = inputs .setdefault (argument , OrderedDict ())
332
- input_definition ["type" ] = kind if isinstance (kind , str ) else kind . __doc__
338
+ input_definition ["type" ] = kind if isinstance (kind , str ) else _doc ( kind )
333
339
default = self .defaults .get (argument , None )
334
340
if default is not None :
335
341
input_definition ["default" ] = default
@@ -505,7 +511,7 @@ def exit(self, status=0, message=None):
505
511
if option in self .interface .input_transformations :
506
512
transform = self .interface .input_transformations [option ]
507
513
kwargs ["type" ] = transform
508
- kwargs ["help" ] = transform . __doc__
514
+ kwargs ["help" ] = _doc ( transform )
509
515
if transform in (list , tuple ) or isinstance (transform , types .Multiple ):
510
516
kwargs ["action" ] = "append"
511
517
kwargs ["type" ] = Text ()
@@ -588,9 +594,12 @@ def exit_callback(message):
588
594
589
595
for field , type_handler in self .reaffirm_types .items ():
590
596
if field in pass_to_function :
591
- pass_to_function [field ] = self .initialize_handler (
592
- type_handler , pass_to_function [field ], context = context
593
- )
597
+ if not pass_to_function [field ] and type_handler in (list , tuple , hug .types .Multiple ):
598
+ pass_to_function [field ] = type_handler (())
599
+ else :
600
+ pass_to_function [field ] = self .initialize_handler (
601
+ type_handler , pass_to_function [field ], context = context
602
+ )
594
603
595
604
if getattr (self , "validate_function" , False ):
596
605
errors = self .validate_function (pass_to_function )
0 commit comments