diff --git a/tests/test_rich_utils.py b/tests/test_rich_utils.py index bd6e58799f..b7549ee57a 100644 --- a/tests/test_rich_utils.py +++ b/tests/test_rich_utils.py @@ -5,7 +5,7 @@ import typer.completion from typer.testing import CliRunner -from tests.utils import needs_rich +from tests.utils import needs_rich, normalize_rich_output runner = CliRunner() @@ -298,3 +298,18 @@ def run(name: str) -> None: usage_line = result.output.splitlines()[0] assert usage_line.startswith("Usage: typer [path_or_module] run [OPTIONS] {name}") assert "Try 'typer [path_or_module] run --help' for help." in result.output + + +@needs_rich +def test_rich_utils_show_default_empty_string() -> None: + app = typer.Typer() + + @app.command() + def main( + name: str = typer.Option("", help="Name to greet", show_default=True), + ) -> None: + print(f"Hello {name}") + + result = runner.invoke(app, ["--help"]) + assert result.exit_code == 0 + assert '[default: ""]' in normalize_rich_output(result.stdout) diff --git a/typer/core.py b/typer/core.py index 97f96d89ab..c4aa9e0f2d 100644 --- a/typer/core.py +++ b/typer/core.py @@ -130,6 +130,8 @@ def _get_default_string( and not default_value ): default_string = "" + elif default_value == "": + default_string = '""' elif default_value is None: default_string = "" else: