Skip to content

Commit 3cf0b3e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c3daaf0 commit 3cf0b3e

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

examples/pathcomplete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def get_main_parser():
1414
parser = argparse.ArgumentParser(prog="pathcomplete")
15-
shtab.add_argument_to(parser, ["-s", "--print-completion"]) # magic!
15+
shtab.add_argument_to(parser, ["-s", "--print-completion"]) # magic!
1616

1717
# file & directory tab complete
1818
parser.add_argument("file_all", nargs="?").complete = shtab.FILE

shtab/__init__.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
from functools import total_ordering
1919
from itertools import starmap
2020
from string import Template
21-
from typing import Any, Dict, List, Sequence, Tuple, Mapping
21+
from typing import Any, Dict, List, Mapping
2222
from 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'
2626
try:
@@ -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

6463
class _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

Comments
 (0)