Click option completion callback doesn't have access to context.params for parsed values of already typed arguments.
Author: coreegorCreated Feb 4, 2022Updated Aug 19, 2026
Labelsshell completiontyping
Click option completion callback doesn't have access to context.params for parsed values of already typed arguments during shell completion:
import click
def test_completer(ctx, param, incomplete):
import sys
print(f"1: {param= }", file=sys.stderr)
print(f"2: {incomplete= }", file=sys.stderr)
print(f"3: {ctx.params = }", file=sys.stderr)
return []
@click.command()
@click.argument('type', shell_complete=test_completer)
@click.option('--test', shell_complete=test_completer)
def app(type, count):
passOutput:
app foo --test [TAB] [TAB]
1: param= <Option test>
2: incomplete= ''
3: ctx.params = {'type': None, 'test': None}Thus the context inside option callback does not have access to already typed argument.
But vice versa works:
app --test bar [TAB] [TAB]
1: param= <Argument type>
2: incomplete= ''
3: ctx.params = {'test': 'bar', 'type': None}The context inside argument callback have access to already typed option.
I think it should be the same in both cases.
Environment:
- Python version: 3.8
- Click version: 8.0.3
Source: pallets/click