Skip to content

Support show_default string in prompts#3165

Closed
MirrorDNA-Reflection-Protocol wants to merge 3 commits intopallets:stablefrom
MirrorDNA-Reflection-Protocol:fix-show-default-string-in-prompt
Closed

Support show_default string in prompts#3165
MirrorDNA-Reflection-Protocol wants to merge 3 commits intopallets:stablefrom
MirrorDNA-Reflection-Protocol:fix-show-default-string-in-prompt

Conversation

@MirrorDNA-Reflection-Protocol
Copy link
Copy Markdown

Summary

Fixes #2836

When show_default is set to a string on an Option with prompt=True, the string was only used in the help text but not in the actual prompt. Now the custom string is also displayed in the prompt, matching the behavior of help text.

Before

@click.option('--name', default='default', show_default='show_default', prompt=True)

Help: --name TEXT [default: (show_default)]
Prompt: Name [default]: ✗ (shows actual default, not custom string)

After

Help: --name TEXT [default: (show_default)]
Prompt: Name [(show_default)]: ✓ (now shows custom string)

Changes

  1. _build_prompt(): Updated to accept str | bool for show_default. When it's a string, display it in parentheses (matching the help text format).

  2. prompt(): Updated signature to accept str | bool for show_default parameter, and updated docstring.

  3. Option.prompt_for_value(): Now passes show_default to prompt() regardless of type (previously only passed it when it was a bool).

Testing

Manually tested with the reproduction case from the issue. The prompt now correctly shows the custom show_default string.

@kdeldycke
Copy link
Copy Markdown
Collaborator

This looks like a copy of #2837 which has been closed by the original author. I guess I can rebase it on top of stable for a future release.

#3262 on the other hand is a copy of that one.

@kdeldycke kdeldycke added bug f:prompt feature: prompt for input labels Mar 25, 2026
@kdeldycke kdeldycke added this to the 8.3.3 milestone Mar 25, 2026
@kdeldycke kdeldycke changed the title Support show_default string in prompts Support show_default string in prompts Mar 25, 2026
@kdeldycke kdeldycke changed the base branch from main to stable March 25, 2026 20:35
@kdeldycke kdeldycke force-pushed the fix-show-default-string-in-prompt branch from 3f4eb62 to bf4b0bb Compare March 25, 2026 20:39
@kdeldycke
Copy link
Copy Markdown
Collaborator

Just added some tests on top of the original PR, including edge-cases and UNSET sentinel. Refactored the code a bit to streamline the code and reduce diff.

This PR is ready to be merged upstream on top of stable for the upcoming 8.3.3 release.

Paul and others added 3 commits April 8, 2026 16:52
Fixes pallets#2836

When show_default is set to a string on an Option with prompt=True,
the string was only used in the help text but not in the actual prompt.
Now the custom string is also shown in the prompt.

Changes:
- Update _build_prompt() to accept str | bool for show_default
- When show_default is a string, display it in parentheses like the help text
- Update prompt() signature to accept str | bool for show_default
- Pass show_default to prompt() regardless of type (was only passing bool)

Before:
  Help: --name TEXT  [default: (show_default)]
  Prompt: Name [default]:

After:
  Help: --name TEXT  [default: (show_default)]
  Prompt: Name [(show_default)]:
@kdeldycke kdeldycke force-pushed the fix-show-default-string-in-prompt branch from f20eb46 to c29e83f Compare April 8, 2026 14:52
@kdeldycke kdeldycke requested review from Rowlando13 and davidism April 8, 2026 14:59
@davidism davidism closed this Apr 8, 2026
@davidism
Copy link
Copy Markdown
Member

davidism commented Apr 8, 2026

AI generated

@kdeldycke
Copy link
Copy Markdown
Collaborator

kdeldycke commented Apr 8, 2026

@davidism : this PR may have been initially AI generated, but still fix a legitimate issue. That's why I took over it 2 weeks ago to amend and fix its slop. See the comment history.

Now that 8.3.2 has been release, I propose to start the 8.3.3 merging phase with this PR first: it is addressing an issue that a lot of AI have tried to solve in the past few weeks. So merging this will cut all the AI generated siblings.

@kdeldycke kdeldycke reopened this Apr 8, 2026
@davidism davidism closed this Apr 8, 2026
@davidism
Copy link
Copy Markdown
Member

davidism commented Apr 8, 2026

I'm not interested in cleaning up AI generated code. I don't want those contributions. I'm sorry you put time into this, but I'd rather that time be spent on creating a PR by hand rather than laundering an AI contribution

Look at the users contribution graph. It's obvious that they're not putting time into anything they're doing. I'm not interested in encouraging that behavior.

@kdeldycke
Copy link
Copy Markdown
Collaborator

I'm not interested in cleaning up AI generated code. I don't want those contributions. I'm sorry you put time into this, but I'd rather that time be spent on creating a PR by hand rather than laundering an AI contribution

Look at the users contribution graph. It's obvious that they're not putting time into anything they're doing. I'm not interested in encouraging that behavior.

I understand. When I started working on that issue I realized we had a human-contributed solution at #2837. But the initial user deleted his forked repository so I could not rework its contribution within the #2837 PR. So I defaulted to the oldest PR which is this one. I wasn't 100% sure this PR was AI-generated so with the benefits of the doubt, and to not erase the original author commit infos, I decided to build on top of it.

I can recreate a clean PR with my modifications to fix #2836 once and for all.

@davidism
Copy link
Copy Markdown
Member

davidism commented Apr 8, 2026

You can still get the patch for a PR, even if the branch has been deleted by appending .patch to the URL. You can apply that in a new branch to re-create the PR while preserving that users credit.

@kdeldycke
Copy link
Copy Markdown
Collaborator

This PR has been superseded by #3328.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug f:prompt feature: prompt for input

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