pallets / pallets/click

Click evaluates default callbacks during tab-completion

Open
#2,614 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

shell completion
Dominant language
Python
Stars
17.7k
Forks
2.4k
Avg merge
1d 30m
Merged PRs (30d)
18

Description

In our app we pass certain defaults via callbacks because they are expensive to calculate. Specifically we want a snappy tab completion. However, it seems that since Click 8.0 the defaults are evaluated even during the tab-autocompletion. I am not sure if this is an expected behaviour or a bug?

It seems that before v8 the behaviour was different. You can see that in the API docs, in an (apparently outdated) comment about resilient_parsing context parameter. https://click.palletsprojects.com/en/8.1.x/api/#click.Context

resilient_parsing (bool) – if this flag is enabled then Click will parse without any interactivity or callback invocation. Default values will also be ignored. This is useful for implementing things such as completion support.

But looking through the core.py code, this flag does not seem honored in the relevant code paths AFAIK. Before that there was even an explicit flag ignore_default_values, which was removed here. https://github.com/pallets/click/commit/02202b6246b0c4a13e96268ce4eb59c2a1349c6c#diff-89531a2fdd908d78f3d3e9bb04de62cb9ad7fd27454da83249937ac29c6f683aR1438

If this is an expected behaviour, I would appreciate advice as to how to override it. Thanks!

Environment:

  • Python version: 3.10.6
  • Click version: 8.1.3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the resilient_parsing handling in core.py and compare it with the Context API documentation and the referenced commit that removed ignore_default_values. Reproduce tab completion with an expensive default callback and verify whether the callback is invoked; done means the behavior is clarified or corrected consistently with the documented completion behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.