From 3c3d22f5ec9e2ea1118b64dc8afb7b0eb5d461f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar=20Su=C3=A1stegui?= Date: Mon, 30 Mar 2026 02:28:37 -0600 Subject: [PATCH] fix: show string show_default value in prompt, not just in help text 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 #2836 --- src/click/core.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index 6adc65ccd6..dc840041d5 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -3145,17 +3145,25 @@ def prompt_for_value(self, ctx: Context) -> t.Any: default = bool(default) return confirm(self.prompt, default) - # If show_default is set to True/False, provide this to `prompt` as well. For - # non-bool values of `show_default`, we use `prompt`'s default behavior + # If show_default is set to True/False, provide this to `prompt` as well. + # If show_default is a string, display that string as the default label + # in the prompt (e.g. "Name [show_default]: ") instead of the raw default + # value. This matches the behaviour already implemented for the help text. prompt_kwargs: t.Any = {} - if isinstance(self.show_default, bool): + prompt_default = None if default is UNSET else default + + if isinstance(self.show_default, str): + # Use the custom string as the displayed default in the prompt. + prompt_kwargs["show_default"] = True + prompt_default = self.show_default + elif isinstance(self.show_default, bool): prompt_kwargs["show_default"] = self.show_default return prompt( self.prompt, # Use ``None`` to inform the prompt() function to reiterate until a valid # value is provided by the user if we have no default. - default=None if default is UNSET else default, + default=prompt_default, type=self.type, hide_input=self.hide_input, show_choices=self.show_choices,