Click option completion callback doesn't have access to context.params for parsed values of already typed arguments.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.7k
- Forks
- 2.3k
- Avg merge
- 1d 30m
- Merged PRs (30d)
- 18
Description
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):
pass
Output:
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproduction in the issue with Click's shell completion callbacks and compare the context passed to the option and argument completers. Done means an option completer can access already typed argument values just as the argument completer accesses typed option values, with a regression test covering both orders.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100