Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion tests/test_rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading