Skip to content

Fix show_default string not displayed in prompts#3262

Closed
oaksprout wants to merge 1 commit intopallets:mainfrom
oaksprout:fix-show-default-string-in-prompt
Closed

Fix show_default string not displayed in prompts#3262
oaksprout wants to merge 1 commit intopallets:mainfrom
oaksprout:fix-show-default-string-in-prompt

Conversation

@oaksprout
Copy link

Summary

When show_default is set to a custom string on an option with prompt=True, the help text correctly displays the custom string (e.g. [default: (show_default)]), but the interactive prompt displays the actual default value instead.

This PR fixes the inconsistency so the prompt also displays the custom show_default string:

@click.option("--name", default="default", show_default="custom label", prompt=True)

Before: Name [default]:
After: Name [custom label]:

Changes

  • Updated _build_prompt in termui.py to accept show_default as bool | str and display the string when provided
  • Updated prompt() signature to accept show_default: bool | str
  • Updated Option.prompt_func in core.py to pass string show_default values through to prompt()
  • Added regression test

Fixes #2836

When show_default is set to a custom string on an option with prompt=True,
the prompt now displays that string instead of the actual default value,
matching the behavior already present in help text.

Fixes pallets#2836
@davidism davidism closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

show_default as a string isn't used in prompts as the default shown

2 participants