@@ -667,7 +667,7 @@ def _complete_for_arg(self, action: argparse.Action,
667667
668668 if callable (arg_choices [0 ]):
669669 completer = arg_choices [0 ]
670- elif isinstance ( arg_choices [ 0 ], str ) and callable ( getattr ( self . _cmd2_app , arg_choices [ 0 ])) :
670+ else :
671671 completer = getattr (self ._cmd2_app , arg_choices [0 ])
672672
673673 # extract the positional and keyword arguments from the tuple
@@ -678,19 +678,16 @@ def _complete_for_arg(self, action: argparse.Action,
678678 list_args = arg_choices [index ]
679679 elif isinstance (arg_choices [index ], dict ):
680680 kw_args = arg_choices [index ]
681- try :
682- # call the provided function differently depending on the provided positional and keyword arguments
683- if list_args is not None and kw_args is not None :
684- return completer (text , line , begidx , endidx , * list_args , ** kw_args )
685- elif list_args is not None :
686- return completer (text , line , begidx , endidx , * list_args )
687- elif kw_args is not None :
688- return completer (text , line , begidx , endidx , ** kw_args )
689- else :
690- return completer (text , line , begidx , endidx )
691- except TypeError :
692- # assume this is due to an incorrect function signature, return nothing.
693- return []
681+
682+ # call the provided function differently depending on the provided positional and keyword arguments
683+ if list_args is not None and kw_args is not None :
684+ return completer (text , line , begidx , endidx , * list_args , ** kw_args )
685+ elif list_args is not None :
686+ return completer (text , line , begidx , endidx , * list_args )
687+ elif kw_args is not None :
688+ return completer (text , line , begidx , endidx , ** kw_args )
689+ else :
690+ return completer (text , line , begidx , endidx )
694691 else :
695692 return self ._cmd2_app .basic_complete (text , line , begidx , endidx ,
696693 self ._resolve_choices_for_arg (action , used_values ))
@@ -704,32 +701,17 @@ def _resolve_choices_for_arg(self, action: argparse.Action, used_values=()) -> L
704701 # is the argument a string? If so, see if we can find an attribute in the
705702 # application matching the string.
706703 if isinstance (args , str ):
707- try :
708- args = getattr (self ._cmd2_app , args )
709- except AttributeError :
710- # Couldn't find anything matching the name
711- return []
704+ args = getattr (self ._cmd2_app , args )
712705
713706 # is the provided argument a callable. If so, call it
714707 if callable (args ):
715708 try :
716- try :
717- args = args (self ._cmd2_app )
718- except TypeError :
719- args = args ()
709+ args = args (self ._cmd2_app )
720710 except TypeError :
721- return []
722-
723- try :
724- iter (args )
725- except TypeError :
726- pass
727- else :
728- # filter out arguments we already used
729- args = [arg for arg in args if arg not in used_values ]
711+ args = args ()
730712
731- if len ( args ) > 0 :
732- return args
713+ # filter out arguments we already used
714+ return [ arg for arg in args if arg not in used_values ]
733715
734716 return []
735717
0 commit comments