click icon indicating copy to clipboard operation
click copied to clipboard

Click evaluates default callbacks during tab-completion

Open danielhollas opened this issue 2 years ago • 0 comments

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

danielhollas avatar Sep 28 '23 14:09 danielhollas