click
click copied to clipboard
Empty string default values are not displayed
If an option has a default value of "", the show_default option does not display anything.
Reproducible example:
import click
@click.group()
def test_cli() -> None:
pass
@test_cli.command(help="Test CLI")
@click.option("--test_value", type=str, default="", show_default=True)
def test_function(
test_value: str
) -> None:
print(test_value)
@click.group()
def cli() -> None:
pass
cli.add_command(test_cli)
cli()
Expected to see a default displayed. Actual behavior:

Environment:
- Python version: 3.11.3
- Click version: 8.0.3
I solved this by using the trick found under Dynamic Defaults for Prompts but I don't think the documentation mentions elsewhere that show_default can be a non-boolean value. Regardless, it still doesn't show for prompts, where the only visual signifier is the empty pair of brackets.
I'm working on this at the PyCon US 2024 sprints.