fix: show string show_default value in prompt, not just in help text#3295
Closed
juliosuas wants to merge 1 commit intopallets:mainfrom
Closed
fix: show string show_default value in prompt, not just in help text#3295juliosuas wants to merge 1 commit intopallets:mainfrom
juliosuas wants to merge 1 commit intopallets:mainfrom
Conversation
When show_default is set to a custom string on an Option with prompt=True, the string was correctly displayed in the help text but not in the prompt itself. The prompt would show the raw default value instead. Root cause: the code path that calls termui.prompt() only forwarded show_default when it was a bool. For string values it passed nothing, so the prompt fell back to displaying the actual default. Fix: when show_default is a str, pass it as the prompt's default parameter (which controls the displayed label) and set show_default=True so _build_prompt includes it in the prompt text. The real default value is still used internally for validation; only the displayed label changes. Before: Name [default]: After: Name [my_custom_label]: Fixes pallets#2836
Author
|
Wanted to add some context in case it's helpful for review: The issue is subtle — Python 3.14 added I also confirmed the fix works by writing a quick test: |
Collaborator
|
This is already covered by #3165 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2836.
When
show_defaultis set to a string on a promptedOption, the string is correctly shown in the help text but not in the interactive prompt — the raw default value is displayed instead.Root Cause
In
Option.prompt_for_value(), theshow_defaultvalue is only forwarded totermui.prompt()when it is abool:When
show_defaultis a string, nothing is passed toprompt(), which falls back to showing the realdefaultvalue.Fix
When
show_defaultis astr, pass it as thedefaultargument (which controls the label shown in brackets) and setshow_default=True:Before / After
Name [real_default]:Name [my_label]:The help text already showed
[default: (my_label)]correctly — this brings the prompt into parity.Testing
Added a manual test that verifies the custom string appears in the prompt output.