Skip to content

Fix show_default string not shown in prompt (#2836)#3280

Closed
r266-tech wants to merge 2 commits intopallets:mainfrom
r266-tech:fix-show-default-prompt
Closed

Fix show_default string not shown in prompt (#2836)#3280
r266-tech wants to merge 2 commits intopallets:mainfrom
r266-tech:fix-show-default-prompt

Conversation

@r266-tech
Copy link
Copy Markdown

Description

Fixes #2836

When show_default is a string and prompt=True, the custom string was ignored and the actual default value was shown in the prompt instead.

Before:

$ python cli.py
Name [default]:

After:

$ python cli.py
Name [custom]:

Changes

  • src/click/core.py: Pass show_default to prompt() regardless of its type (bool or str), not just for bool values
  • src/click/termui.py: Updated _build_prompt() and prompt() signature to accept str for show_default. When it is a string, it is displayed in the prompt bracket instead of the formatted default value
  • tests/test_options.py: Added test test_show_default_string_in_prompt

All existing tests pass (1320 passed, 22 skipped).

Anonymous Contributor and others added 2 commits March 23, 2026 02:33
When show_default is a string and prompt=True, the custom string
was ignored and the actual default value was shown in the prompt instead.

This change:
- Passes show_default to prompt() regardless of its type (bool or str)
- Updates _build_prompt() and prompt() to accept str for show_default
- When show_default is a string, it is displayed in the prompt bracket
  instead of the formatted default value

Fixes pallets#2836
@davidism davidism closed this Mar 22, 2026
@kdeldycke kdeldycke added this to the 8.3.3 milestone Mar 25, 2026
@kdeldycke kdeldycke added bug f:prompt feature: prompt for input invalid labels Mar 25, 2026
@kdeldycke
Copy link
Copy Markdown
Collaborator

This is a copy of #3165, #2837 and #3262

@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