@@ -755,14 +755,15 @@ def recurse_parser(cparser, positional_idx, requirements=None):
755755def complete (parser : ArgumentParser , shell : str = "bash" , root_prefix : Opt [str ] = None ,
756756 preamble : Union [str , Dict ] = "" , choice_functions : Opt [Any ] = None ) -> str :
757757 """
758- parser : argparse.ArgumentParser
759- shell : str ( bash/zsh)
760- root_prefix : str or `None`
758+ shell:
759+ bash/zsh/tcsh
760+ root_prefix:
761761 prefix for shell functions to avoid clashes (default: "_{parser.prog}")
762- preamble : dict or str
762+ preamble:
763763 mapping shell to text to prepend to generated script
764764 (e.g. `{"bash": "_myprog_custom_function(){ echo hello }"}`)
765- choice_functions : deprecated
765+ choice_functions:
766+ *deprecated*
766767
767768 N.B. `parser.add_argument().complete = ...` can be used to define custom
768769 completions (e.g. filenames). See <../examples/pathcomplete.py>.
@@ -778,7 +779,7 @@ def complete(parser: ArgumentParser, shell: str = "bash", root_prefix: Opt[str]
778779 )
779780
780781
781- def completion_action (parent = None , preamble = "" ):
782+ def completion_action (parent : Opt [ ArgumentParser ] = None , preamble : Union [ str , Dict ] = "" ):
782783 class PrintCompletionAction (_ShtabPrintCompletionAction ):
783784 def __call__ (self , parser , namespace , values , option_string = None ):
784785 print (complete (parent or parser , values , preamble = preamble ))
@@ -788,19 +789,17 @@ def __call__(self, parser, namespace, values, option_string=None):
788789
789790
790791def add_argument_to (
791- parser ,
792- option_string = "--print-completion" ,
793- help = "print shell completion script" ,
794- parent = None ,
795- preamble = "" ,
792+ parser : ArgumentParser ,
793+ option_string : Union [ str , List [ str ]] = "--print-completion" ,
794+ help : str = "print shell completion script" ,
795+ parent : Opt [ ArgumentParser ] = None ,
796+ preamble : Union [ str , Dict ] = "" ,
796797):
797798 """
798- parser : argparse.ArgumentParser
799- option_string : str or list[str]
799+ option_string:
800800 iff positional (no `-` prefix) then `parser` is assumed to actually be
801801 a subparser (subcommand mode)
802- help : str
803- parent : argparse.ArgumentParser
802+ parent:
804803 required in subcommand mode
805804 """
806805 if isinstance (option_string , str ):
0 commit comments