Skip to content

Skip default evaluation and callbacks during resilient parsing#3356

Closed
barry3406 wants to merge 1 commit into
pallets:stablefrom
barry3406:fix/resilient-parsing-skip-default-callbacks
Closed

Skip default evaluation and callbacks during resilient parsing#3356
barry3406 wants to merge 1 commit into
pallets:stablefrom
barry3406:fix/resilient-parsing-skip-default-callbacks

Conversation

@barry3406
Copy link
Copy Markdown

During shell completion, Context.resilient_parsing is set to True.
Its documentation states:

if this flag is enabled then Click will parse without any interactivity
or callback invocation. Default values will also be ignored.

However, Parameter.consume_value still evaluated a default= callable
and Parameter.process_value still invoked the parameter's callback
while completion was running. This produced unwanted side effects during
tab-completion for callers that pass an expensive callable as default
or attach a callback with side effects.

Now both paths check ctx.resilient_parsing and skip the default/callback,
matching the documented behavior. The _resolve_context docstring in
shell_completion.py already said "it doesn't trigger input prompts or
callbacks" - this brings the implementation in line.

fixes #2614

Changes

  • Parameter.consume_value: skip self.get_default(ctx) when
    ctx.resilient_parsing is True.
  • Parameter.process_value: skip self.callback invocation when
    ctx.resilient_parsing is True.
  • Option.process_value: same skip for the bool-flag early-return
    branch.
  • Three tests in tests/test_shell_completion.py covering default=
    callables, parameter callback, and bool flag callback.
  • CHANGES.rst entry added under Unreleased.

During shell completion, Context.resilient_parsing is set to True.
Its documentation states that parsing happens without any interactivity
or callback invocation, and that default values are ignored. However,
``Parameter.consume_value`` still called the ``default=`` callable and
``Parameter.process_value`` still invoked the parameter's ``callback``,
which could produce unwanted side effects during tab-completion.

Now both paths honor ``ctx.resilient_parsing``, matching the docs.
@davidism davidism closed this Apr 19, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants