1818from functools import total_ordering
1919from itertools import starmap
2020from string import Template
21- from typing import Any , Dict , List , Sequence , Tuple , Mapping
21+ from typing import Any , Dict , List , Mapping
2222from typing import Optional as Opt
23- from typing import Union
23+ from typing import Sequence , Tuple , Union
2424
2525# version detector. Precedence: installed dist, git, 'UNKNOWN'
2626try :
@@ -55,10 +55,9 @@ def fglob(fglob: str):
5555 '''Glob files'''
5656 return {
5757 '__glob__' : fglob ,
58- 'bash' : '_shtab_compgen_files' , # Uses `__glob__` internally
58+ 'bash' : '_shtab_compgen_files' , # Uses `__glob__` internally
5959 'zsh' : f"_files -g '{ fglob } '" ,
60- 'tcsh' : f'f:{ fglob } ' ,
61- }
60+ 'tcsh' : f'f:{ fglob } ' ,}
6261
6362
6463class _ShtabPrintCompletionAction (Action ):
@@ -140,9 +139,11 @@ def complete2pattern(opt_complete, shell: str, choice_type2fn) -> str:
140139 return choice_type2fn [opt_complete ]
141140
142141
143- def bash_complete2compgen (opt_complete : Mapping [str , str ], shell : str ,
144- choice_type2fn : Mapping [str , str ],
145- ) -> Tuple [str , Tuple [str ]]:
142+ def bash_complete2compgen (
143+ opt_complete : Mapping [str , str ],
144+ shell : str ,
145+ choice_type2fn : Mapping [str , str ],
146+ ) -> Tuple [str , Tuple [str ]]:
146147 # Same inputs as `complete2pattern`
147148 options = []
148149 if isinstance (opt_complete , dict ):
@@ -220,11 +221,11 @@ def recurse(parser, prefix):
220221
221222 if hasattr (positional , "complete" ):
222223 # shtab `.complete = ...` functions
223- comp_gen , comp_genopts = bash_complete2compgen (positional .complete , "bash" , choice_type2fn )
224+ comp_gen , comp_genopts = bash_complete2compgen (positional .complete , "bash" ,
225+ choice_type2fn )
224226 compgens .extend ([
225227 f"{ prefix } _pos_{ i } _COMPGEN={ comp_gen } " ,
226- f"{ prefix } _pos_{ i } _COMPGEN_options={ bash_listify (comp_genopts )} " ,
227- ])
228+ f"{ prefix } _pos_{ i } _COMPGEN_options={ bash_listify (comp_genopts )} " ,])
228229
229230 if positional .choices :
230231 # choices (including subparsers & shtab `.complete` functions)
@@ -238,8 +239,7 @@ def recurse(parser, prefix):
238239 log .debug (f"Choice.{ choice .type } :{ prefix } :{ positional .dest } " )
239240 compgens .extend ([
240241 f"{ prefix } _pos_{ i } _COMPGEN={ choice_type2fn [choice .type ]} " ,
241- f"{ prefix } _pos_{ i } _COMPGEN_options=()" ,
242- ])
242+ f"{ prefix } _pos_{ i } _COMPGEN_options=()" ,])
243243 elif isinstance (positional .choices , dict ):
244244 # subparser, so append to list of subparsers & recurse
245245 log .debug ("subcommand:%s" , choice )
@@ -269,7 +269,8 @@ def recurse(parser, prefix):
269269 this_positional_choices .append (str (choice ))
270270
271271 if this_positional_choices :
272- choices .append (f"{ prefix } _pos_{ i } _choices={ bash_listify (this_positional_choices )} " )
272+ choices .append (
273+ f"{ prefix } _pos_{ i } _choices={ bash_listify (this_positional_choices )} " )
273274
274275 # skip default `nargs` values
275276 if positional .nargs not in (None , "1" , "?" ):
@@ -290,7 +291,8 @@ def recurse(parser, prefix):
290291 for option_string in optional .option_strings :
291292 if hasattr (optional , "complete" ):
292293 # shtab `.complete = ...` functions
293- comp_gen , comp_genopts = bash_complete2compgen (optional .complete , "bash" , choice_type2fn )
294+ comp_gen , comp_genopts = bash_complete2compgen (optional .complete , "bash" ,
295+ choice_type2fn )
294296 compgens .extend ([
295297 f"{ prefix } _{ wordify (option_string )} _COMPGEN={ comp_gen } " ,
296298 f"{ prefix } _{ wordify (option_string )} _COMPGEN_options={ bash_listify (comp_genopts )} " ,
@@ -306,14 +308,15 @@ def recurse(parser, prefix):
306308 log .debug (f"Choice.{ choice .type } :{ prefix } :{ optional .dest } " )
307309 compgens .extend ([
308310 f"{ prefix } _{ wordify (option_string )} _COMPGEN={ choice_type2fn [choice .type ]} " ,
309- f"{ prefix } _{ wordify (option_string )} _COMPGEN_options=()" ,
310- ])
311+ f"{ prefix } _{ wordify (option_string )} _COMPGEN_options=()" ,])
311312 else :
312313 # simple choice
313314 this_optional_choices .append (str (choice ))
314315
315316 if this_optional_choices :
316- choices .append (f"{ prefix } _{ wordify (option_string )} _choices={ bash_listify (this_optional_choices )} " )
317+ choices .append (
318+ f"{ prefix } _{ wordify (option_string )} _choices={ bash_listify (this_optional_choices )} "
319+ )
317320
318321 # Check for nargs.
319322 if optional .nargs is not None and optional .nargs != 1 :
0 commit comments