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
Copy Markdown

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
@kdeldycke
Copy link
Copy Markdown
Collaborator

kdeldycke commented Mar 25, 2026

This PR has been closed as a copy of both #3165, #2837 and #3280

@kdeldycke kdeldycke added f:prompt feature: prompt for input invalid bug labels Mar 25, 2026
@kdeldycke kdeldycke added this to the 8.3.3 milestone Mar 25, 2026
@kdeldycke kdeldycke changed the title Fix show_default string not displayed in prompts Fix show_default string not displayed in prompts Mar 25, 2026
@kdeldycke
Copy link
Copy Markdown
Collaborator

A PR is ready to be merged at: #3165

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug f:prompt feature: prompt for input invalid

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

3 participants