From b0538d8022171c2548a9b3155b3a8ca16e3754d5 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 11:00:38 +0200 Subject: [PATCH 1/9] updated tests for more consistent & clean metavar printing --- tests/assets/cli/multiapp-docs-title.md | 8 +-- tests/assets/cli/multiapp-docs.md | 8 +-- tests/assets/cli/richformattedapp-docs.md | 6 +- tests/test_cli/test_help.py | 2 +- tests/test_core.py | 60 +++++++++++++++++++ tests/test_prog_name.py | 2 +- tests/test_rich_markup_mode.py | 2 +- tests/test_rich_utils.py | 29 +++++---- .../test_default/test_tutorial001.py | 2 +- .../test_default/test_tutorial002.py | 2 +- .../test_envvar/test_tutorial001.py | 4 +- .../test_envvar/test_tutorial002.py | 2 +- .../test_envvar/test_tutorial003.py | 2 +- .../test_help/test_tutorial001.py | 8 +-- .../test_help/test_tutorial002.py | 4 +- .../test_help/test_tutorial003.py | 4 +- .../test_help/test_tutorial004.py | 4 +- .../test_help/test_tutorial005.py | 2 +- .../test_help/test_tutorial008.py | 4 +- .../test_optional/test_tutorial000.py | 2 +- .../test_optional/test_tutorial001.py | 4 +- .../test_optional/test_tutorial002.py | 2 +- .../test_optional/test_tutorial003.py | 4 +- .../test_arguments/test_tutorial001.py | 4 +- .../test_help/test_tutorial001.py | 4 +- .../test_help/test_tutorial007.py | 2 +- .../test_first_steps/test_tutorial002.py | 2 +- .../test_first_steps/test_tutorial003.py | 2 +- .../test_first_steps/test_tutorial004.py | 4 +- .../test_first_steps/test_tutorial005.py | 4 +- .../test_tutorial002.py | 2 +- .../test_help/test_tutorial003.py | 2 +- .../test_help/test_tutorial004.py | 2 +- .../test_name/test_tutorial001.py | 2 +- .../test_name/test_tutorial002.py | 2 +- .../test_name/test_tutorial003.py | 2 +- .../test_name/test_tutorial004.py | 2 +- .../test_name/test_tutorial005.py | 2 +- .../test_password/test_tutorial001.py | 2 +- .../test_password/test_tutorial002.py | 2 +- .../test_prompt/test_tutorial001.py | 2 +- .../test_prompt/test_tutorial002.py | 2 +- .../test_prompt/test_tutorial003.py | 2 +- .../test_tutorial001_tutorial002.py | 4 +- .../test_datetime/test_tutorial001.py | 2 +- .../test_enum/test_tutorial001.py | 2 +- .../test_enum/test_tutorial003.py | 2 +- .../test_enum/test_tutorial004.py | 2 +- .../test_index/test_tutorial001.py | 4 +- .../test_number/test_tutorial001.py | 8 +-- .../test_typer_app/test_tutorial001.py | 2 +- tests/test_types.py | 4 +- 52 files changed, 154 insertions(+), 91 deletions(-) diff --git a/tests/assets/cli/multiapp-docs-title.md b/tests/assets/cli/multiapp-docs-title.md index ffde843736..368275838f 100644 --- a/tests/assets/cli/multiapp-docs-title.md +++ b/tests/assets/cli/multiapp-docs-title.md @@ -65,8 +65,8 @@ $ multiapp sub hello [OPTIONS] **Options**: -* `--name TEXT`: [default: World] -* `--age INTEGER`: The age of the user [default: 0] +* `--name `: [default: World] +* `--age `: The age of the user [default: 0] * `--help`: Show this message and exit. ### `multiapp sub hi` @@ -76,12 +76,12 @@ Say Hi **Usage**: ```console -$ multiapp sub hi [OPTIONS] [USER] +$ multiapp sub hi [OPTIONS] [user] ``` **Arguments**: -* `[USER]`: The name of the user to greet [default: World] +* `[user]`: The name of the user to greet [default: World] **Options**: diff --git a/tests/assets/cli/multiapp-docs.md b/tests/assets/cli/multiapp-docs.md index 67d02568db..e1dad5f804 100644 --- a/tests/assets/cli/multiapp-docs.md +++ b/tests/assets/cli/multiapp-docs.md @@ -65,8 +65,8 @@ $ multiapp sub hello [OPTIONS] **Options**: -* `--name TEXT`: [default: World] -* `--age INTEGER`: The age of the user [default: 0] +* `--name `: [default: World] +* `--age `: The age of the user [default: 0] * `--help`: Show this message and exit. ### `multiapp sub hi` @@ -76,12 +76,12 @@ Say Hi **Usage**: ```console -$ multiapp sub hi [OPTIONS] [USER] +$ multiapp sub hi [OPTIONS] [user] ``` **Arguments**: -* `[USER]`: The name of the user to greet [default: World] +* `[user]`: The name of the user to greet [default: World] **Options**: diff --git a/tests/assets/cli/richformattedapp-docs.md b/tests/assets/cli/richformattedapp-docs.md index 678a2daf6f..a6d1ab1dc3 100644 --- a/tests/assets/cli/richformattedapp-docs.md +++ b/tests/assets/cli/richformattedapp-docs.md @@ -5,13 +5,13 @@ Say cool name of the user [required] -* `[USER_2]`: The world [default: The World] +* `user_1`: The cool name of the user [required] +* `[user_2]`: The world [default: The World] **Options**: diff --git a/tests/test_cli/test_help.py b/tests/test_cli/test_help.py index e829c5801b..3238c0658b 100644 --- a/tests/test_cli/test_help.py +++ b/tests/test_cli/test_help.py @@ -121,7 +121,7 @@ def cmd(value: str) -> None: output_lines = result.output.splitlines() usage_idx = output_lines.index("Usage: very-long-program-name-that-forces-wrap ") args_line = output_lines[usage_idx + 1] - assert args_line.lstrip() == "[OPTIONS] VALUE" + assert args_line.lstrip() == "[OPTIONS] {value}" assert args_line.startswith(" ") diff --git a/tests/test_core.py b/tests/test_core.py index 2cb759918b..c3920ab883 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -377,3 +377,63 @@ def main(names: list[str] = typer.Option(None)): result = runner.invoke(app, [], default_map={"names": "not-a-list"}) assert result.exit_code == 2 assert "Invalid value" in result.output + + +def test_parameter_name_casing(): + app = typer.Typer() + + @app.command() + def main( + arg1: int, + arg2: int = 42, + arg3: int = typer.Argument(...), + ARG4: int = typer.Argument(42), + ARG5: int = typer.Option(...), + arg6: int = typer.Option(42), + arg7: int = typer.Argument(42, metavar="meta7"), + arg8: int = typer.Argument(metavar="ARG8"), + arg9: int = typer.Option(metavar="ARG9"), + ): + print( + f"arg1={arg1} arg2={arg2} arg3={arg3} ARG4={ARG4} ARG5={ARG5} " + f"arg6={arg6} arg7={arg7} arg8={arg8} arg9={arg9}" + ) + + result = runner.invoke( + app, + [ + "1", + "3", + "4", + "7", + "8", + "--arg2", + "2", + "--ARG5", + "5", + "--arg6", + "6", + "--ARG9", + "9", + ], + ) + assert result.exit_code == 0 + assert ( + "arg1=1 arg2=2 arg3=3 ARG4=4 ARG5=5 arg6=6 arg7=7 arg8=8 arg9=9" + in result.output + ) + + result = runner.invoke(app, ["1", "3", "4", "7", "8", "--ARG5", "5", "--ARG9", "9"]) + assert result.exit_code == 0 + assert ( + "arg1=1 arg2=42 arg3=3 ARG4=4 ARG5=5 arg6=42 arg7=7 arg8=8 arg9=9" + in result.output + ) + + result = runner.invoke(app, ["1", "3", "4", "7", "8", "--arg5", "5", "--ARG9", "9"]) + assert result.exit_code != 0 + assert "No such option: --arg5" in result.output + + result = runner.invoke(app, ["1", "3", "4", "7", "8", "--ARG5", "5", "--arg9", "9"]) + assert result.exit_code != 0 + assert "No such option: --arg9" in result.output diff --git a/tests/test_prog_name.py b/tests/test_prog_name.py index cfb5a3464f..5de6fd3f7a 100644 --- a/tests/test_prog_name.py +++ b/tests/test_prog_name.py @@ -10,4 +10,4 @@ def test_custom_prog_name(): capture_output=True, encoding="utf-8", ) - assert "Usage: custom-name [OPTIONS] I" in result.stdout + assert "Usage: custom-name [OPTIONS] {i}" in result.stdout diff --git a/tests/test_rich_markup_mode.py b/tests/test_rich_markup_mode.py index abfae82790..94fb4c2ae8 100644 --- a/tests/test_rich_markup_mode.py +++ b/tests/test_rich_markup_mode.py @@ -25,7 +25,7 @@ def main(arg: str): assert "Hello World" in result.stdout result = runner.invoke(app, ["--help"]) - assert "ARG [required]" in result.stdout + assert "arg [required]" in result.stdout assert all(c not in result.stdout for c in rounded) diff --git a/tests/test_rich_utils.py b/tests/test_rich_utils.py index beb914b961..6d11652d77 100644 --- a/tests/test_rich_utils.py +++ b/tests/test_rich_utils.py @@ -101,7 +101,7 @@ def main(bar: str): result = runner.invoke(app, ["--help"]) assert "Usage" in result.stdout - assert "BAR" in result.stdout + assert "{bar}" in result.stdout @needs_rich @@ -233,8 +233,8 @@ def main( arg1: int, arg2: int = 42, arg3: int = typer.Argument(...), - arg4: int = typer.Argument(42), - arg5: int = typer.Option(...), + ARG4: int = typer.Argument(42), + ARG5: int = typer.Option(...), arg6: int = typer.Option(42), arg7: int = typer.Argument(42, metavar="meta7"), arg8: int = typer.Argument(metavar="ARG8"), @@ -243,23 +243,26 @@ def main( pass # pragma: no cover result = runner.invoke(app, ["--help"]) - assert "Usage: main [OPTIONS] ARG1 ARG3 [ARG4] [meta7] ARG8 arg9" in result.stdout + assert ( + "Usage: main [OPTIONS] {arg1} {arg3} [ARG4] [meta7] {ARG8} {arg9}" + in result.stdout + ) out_nospace = result.stdout.replace(" ", "") # arguments - assert "arg1INTEGER" in out_nospace - assert "arg3INTEGER" in out_nospace - assert "[arg4]INTEGER" in out_nospace - assert "[meta7]INTEGER" in out_nospace - assert "ARG8INTEGER" in out_nospace - assert "arg9INTEGER" in out_nospace + assert "arg1" in out_nospace + assert "arg3" in out_nospace + assert "[ARG4]" in out_nospace + assert "[meta7]" in out_nospace + assert "ARG8" in out_nospace + assert "arg9" in out_nospace assert "arg7" not in result.stdout.lower() assert "arg8" not in result.stdout assert "ARG9" not in result.stdout # options - assert "arg2INTEGER" in out_nospace - assert "arg5INTEGER" in out_nospace - assert "arg6INTEGER" in out_nospace + assert "--arg2" in out_nospace + assert "--ARG5" in out_nospace + assert "--arg6" in out_nospace diff --git a/tests/test_tutorial/test_arguments/test_default/test_tutorial001.py b/tests/test_tutorial/test_arguments/test_default/test_tutorial001.py index 75104a7d9b..81212ce98b 100644 --- a/tests/test_tutorial/test_arguments/test_default/test_tutorial001.py +++ b/tests/test_tutorial/test_arguments/test_default/test_tutorial001.py @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Arguments" in result.output assert "[default: Wade Wilson]" in result.output diff --git a/tests/test_tutorial/test_arguments/test_default/test_tutorial002.py b/tests/test_tutorial/test_arguments/test_default/test_tutorial002.py index f68b61df82..37eedd779d 100644 --- a/tests/test_tutorial/test_arguments/test_default/test_tutorial002.py +++ b/tests/test_tutorial/test_arguments/test_default/test_tutorial002.py @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Arguments" in result.output assert "[default: (dynamic)]" in result.output diff --git a/tests/test_tutorial/test_arguments/test_envvar/test_tutorial001.py b/tests/test_tutorial/test_arguments/test_envvar/test_tutorial001.py index 689030a258..179f6936fc 100644 --- a/tests/test_tutorial/test_arguments/test_envvar/test_tutorial001.py +++ b/tests/test_tutorial/test_arguments/test_envvar/test_tutorial001.py @@ -27,7 +27,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Arguments" in result.output assert "env var: AWESOME_NAME" in result.output assert "default: World" in result.output @@ -37,7 +37,7 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType): monkeypatch.setattr(typer.core, "HAS_RICH", False) result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Arguments" in result.output assert "env var: AWESOME_NAME" in result.output assert "default: World" in result.output diff --git a/tests/test_tutorial/test_arguments/test_envvar/test_tutorial002.py b/tests/test_tutorial/test_arguments/test_envvar/test_tutorial002.py index 23679b04b5..3d06a1c869 100644 --- a/tests/test_tutorial/test_arguments/test_envvar/test_tutorial002.py +++ b/tests/test_tutorial/test_arguments/test_envvar/test_tutorial002.py @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Arguments" in result.output assert "env var: AWESOME_NAME, GOD_NAME" in result.output assert "default: World" in result.output diff --git a/tests/test_tutorial/test_arguments/test_envvar/test_tutorial003.py b/tests/test_tutorial/test_arguments/test_envvar/test_tutorial003.py index ee979e4762..042620f9a0 100644 --- a/tests/test_tutorial/test_arguments/test_envvar/test_tutorial003.py +++ b/tests/test_tutorial/test_arguments/test_envvar/test_tutorial003.py @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Arguments" in result.output assert "env var: AWESOME_NAME" not in result.output assert "default: World" in result.output diff --git a/tests/test_tutorial/test_arguments/test_help/test_tutorial001.py b/tests/test_tutorial/test_arguments/test_help/test_tutorial001.py index fabe28be28..e2e24fe647 100644 --- a/tests/test_tutorial/test_arguments/test_help/test_tutorial001.py +++ b/tests/test_tutorial/test_arguments/test_help/test_tutorial001.py @@ -26,9 +26,9 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] NAME" in result.output + assert "[OPTIONS] {name}" in result.output assert "Arguments" in result.output - assert "NAME" in result.output + assert "{name}" in result.output assert "The name of the user to greet" in result.output assert "[required]" in result.output @@ -37,9 +37,9 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType): monkeypatch.setattr(typer.core, "HAS_RICH", False) result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] NAME" in result.output + assert "[OPTIONS] {name}" in result.output assert "Arguments" in result.output - assert "NAME" in result.output + assert "{name}" in result.output assert "The name of the user to greet" in result.output assert "[required]" in result.output diff --git a/tests/test_tutorial/test_arguments/test_help/test_tutorial002.py b/tests/test_tutorial/test_arguments/test_help/test_tutorial002.py index 91eb30e375..f3fd10a9d1 100644 --- a/tests/test_tutorial/test_arguments/test_help/test_tutorial002.py +++ b/tests/test_tutorial/test_arguments/test_help/test_tutorial002.py @@ -25,10 +25,10 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] NAME" in result.output + assert "[OPTIONS] {name}" in result.output assert "Say hi to NAME very gently, like Dirk." in result.output assert "Arguments" in result.output - assert "NAME" in result.output + assert "{name}" in result.output assert "The name of the user to greet" in result.output assert "[required]" in result.output diff --git a/tests/test_tutorial/test_arguments/test_help/test_tutorial003.py b/tests/test_tutorial/test_arguments/test_help/test_tutorial003.py index 20bd6b76ea..dc7ef0234c 100644 --- a/tests/test_tutorial/test_arguments/test_help/test_tutorial003.py +++ b/tests/test_tutorial/test_arguments/test_help/test_tutorial003.py @@ -25,10 +25,10 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Say hi to NAME very gently, like Dirk." in result.output assert "Arguments" in result.output - assert "NAME" in result.output + assert "[name]" in result.output assert "Who to greet" in result.output assert "[default: World]" in result.output diff --git a/tests/test_tutorial/test_arguments/test_help/test_tutorial004.py b/tests/test_tutorial/test_arguments/test_help/test_tutorial004.py index 7a20f48979..451e3272ad 100644 --- a/tests/test_tutorial/test_arguments/test_help/test_tutorial004.py +++ b/tests/test_tutorial/test_arguments/test_help/test_tutorial004.py @@ -25,10 +25,10 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Say hi to NAME very gently, like Dirk." in result.output assert "Arguments" in result.output - assert "NAME" in result.output + assert "[name]" in result.output assert "Who to greet" in result.output assert "[default: World]" not in result.output diff --git a/tests/test_tutorial/test_arguments/test_help/test_tutorial005.py b/tests/test_tutorial/test_arguments/test_help/test_tutorial005.py index 8f6d356d81..4cb17b4e86 100644 --- a/tests/test_tutorial/test_arguments/test_help/test_tutorial005.py +++ b/tests/test_tutorial/test_arguments/test_help/test_tutorial005.py @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "Usage: main [OPTIONS] [NAME]" in result.output + assert "Usage: main [OPTIONS] [name]" in result.output assert "Arguments" in result.output assert "Who to greet" in result.output assert "[default: (Deadpoolio the amazing's name)]" in result.output diff --git a/tests/test_tutorial/test_arguments/test_help/test_tutorial008.py b/tests/test_tutorial/test_arguments/test_help/test_tutorial008.py index f21c883434..004dbbcfe1 100644 --- a/tests/test_tutorial/test_arguments/test_help/test_tutorial008.py +++ b/tests/test_tutorial/test_arguments/test_help/test_tutorial008.py @@ -26,7 +26,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Say hi to NAME very gently, like Dirk." in result.output assert "Arguments" not in result.output assert "[default: World]" not in result.output @@ -36,7 +36,7 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType): monkeypatch.setattr(typer.core, "HAS_RICH", False) result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output assert "Say hi to NAME very gently, like Dirk." in result.output assert "Arguments" not in result.output assert "[default: World]" not in result.output diff --git a/tests/test_tutorial/test_arguments/test_optional/test_tutorial000.py b/tests/test_tutorial/test_arguments/test_optional/test_tutorial000.py index 8f0bd34c7f..76d86ed82e 100644 --- a/tests/test_tutorial/test_arguments/test_optional/test_tutorial000.py +++ b/tests/test_tutorial/test_arguments/test_optional/test_tutorial000.py @@ -39,7 +39,7 @@ def test_cli(app: typer.Typer): def test_cli_missing_argument(app: typer.Typer): result = runner.invoke(app) assert result.exit_code == 2 - assert "Missing argument 'NAME'" in result.output + assert "Missing argument 'name'" in result.output def test_script(mod: ModuleType): diff --git a/tests/test_tutorial/test_arguments/test_optional/test_tutorial001.py b/tests/test_tutorial/test_arguments/test_optional/test_tutorial001.py index 7e26b9eb86..60d4b5d30d 100644 --- a/tests/test_tutorial/test_arguments/test_optional/test_tutorial001.py +++ b/tests/test_tutorial/test_arguments/test_optional/test_tutorial001.py @@ -26,7 +26,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_call_no_arg(mod: ModuleType): result = runner.invoke(mod.app) assert result.exit_code != 0 - assert "Missing argument 'NAME'." in result.output + assert "Missing argument 'name'." in result.output def test_call_no_arg_standalone(mod: ModuleType): @@ -40,7 +40,7 @@ def test_call_no_arg_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType): monkeypatch.setattr(typer.core, "HAS_RICH", False) result = runner.invoke(mod.app) assert result.exit_code != 0 - assert "Error: Missing argument 'NAME'" in result.output + assert "Error: Missing argument 'name'" in result.output def test_call_arg(mod: ModuleType): diff --git a/tests/test_tutorial/test_arguments/test_optional/test_tutorial002.py b/tests/test_tutorial/test_arguments/test_optional/test_tutorial002.py index 3e3fdba384..b1b1c9b07b 100644 --- a/tests/test_tutorial/test_arguments/test_optional/test_tutorial002.py +++ b/tests/test_tutorial/test_arguments/test_optional/test_tutorial002.py @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAME]" in result.output + assert "[OPTIONS] [name]" in result.output def test_call_no_arg(mod: ModuleType): diff --git a/tests/test_tutorial/test_arguments/test_optional/test_tutorial003.py b/tests/test_tutorial/test_arguments/test_optional/test_tutorial003.py index 60addad04d..274616e04c 100644 --- a/tests/test_tutorial/test_arguments/test_optional/test_tutorial003.py +++ b/tests/test_tutorial/test_arguments/test_optional/test_tutorial003.py @@ -15,7 +15,7 @@ def test_call_no_arg(): result = runner.invoke(app) assert result.exit_code != 0 - assert "Missing argument 'NAME'." in result.output + assert "Missing argument 'name'." in result.output def test_call_no_arg_standalone(): @@ -29,7 +29,7 @@ def test_call_no_arg_no_rich(monkeypatch: pytest.MonkeyPatch): monkeypatch.setattr(typer.core, "HAS_RICH", False) result = runner.invoke(app) assert result.exit_code != 0 - assert "Error: Missing argument 'NAME'" in result.output + assert "Error: Missing argument 'name'" in result.output def test_call_arg(): diff --git a/tests/test_tutorial/test_commands/test_arguments/test_tutorial001.py b/tests/test_tutorial/test_commands/test_arguments/test_tutorial001.py index 4efc1fe9ef..58ac250108 100644 --- a/tests/test_tutorial/test_commands/test_arguments/test_tutorial001.py +++ b/tests/test_tutorial/test_commands/test_arguments/test_tutorial001.py @@ -13,13 +13,13 @@ def test_help_create(): result = runner.invoke(app, ["create", "--help"]) assert result.exit_code == 0 - assert "create [OPTIONS] USERNAME" in result.output + assert "create [OPTIONS] {username}" in result.output def test_help_delete(): result = runner.invoke(app, ["delete", "--help"]) assert result.exit_code == 0 - assert "delete [OPTIONS] USERNAME" in result.output + assert "delete [OPTIONS] {username}" in result.output def test_create(): diff --git a/tests/test_tutorial/test_commands/test_help/test_tutorial001.py b/tests/test_tutorial/test_commands/test_help/test_tutorial001.py index 9993765b37..751022c673 100644 --- a/tests/test_tutorial/test_commands/test_help/test_tutorial001.py +++ b/tests/test_tutorial/test_commands/test_help/test_tutorial001.py @@ -39,14 +39,14 @@ def test_help(mod: ModuleType): def test_help_create(mod: ModuleType): result = runner.invoke(mod.app, ["create", "--help"]) assert result.exit_code == 0 - assert "create [OPTIONS] USERNAME" in result.output + assert "create [OPTIONS] {username}" in result.output assert "Create a new user with USERNAME." in result.output def test_help_delete(mod: ModuleType): result = runner.invoke(mod.app, ["delete", "--help"]) assert result.exit_code == 0 - assert "delete [OPTIONS] USERNAME" in result.output + assert "delete [OPTIONS] {username}" in result.output assert "Delete a user with USERNAME." in result.output assert "--force" in result.output assert "--no-force" in result.output diff --git a/tests/test_tutorial/test_commands/test_help/test_tutorial007.py b/tests/test_tutorial/test_commands/test_help/test_tutorial007.py index 76c7cb2a4f..7b8fe367ed 100644 --- a/tests/test_tutorial/test_commands/test_help/test_tutorial007.py +++ b/tests/test_tutorial/test_commands/test_help/test_tutorial007.py @@ -36,7 +36,7 @@ def test_main_help(mod: ModuleType): def test_create_help(mod: ModuleType): result = runner.invoke(mod.app, ["create", "--help"]) assert result.exit_code == 0 - assert "create [OPTIONS] USERNAME [LASTNAME]" in result.output + assert "create [OPTIONS] {username} [lastname]" in result.output assert "username" in result.output assert "The username to create" in result.output assert "Secondary Arguments" in result.output diff --git a/tests/test_tutorial/test_first_steps/test_tutorial002.py b/tests/test_tutorial/test_first_steps/test_tutorial002.py index 952f983963..baceee2bc2 100644 --- a/tests/test_tutorial/test_first_steps/test_tutorial002.py +++ b/tests/test_tutorial/test_first_steps/test_tutorial002.py @@ -15,7 +15,7 @@ def test_1(): result = runner.invoke(app, []) assert result.exit_code != 0 - assert "Missing argument 'NAME'" in result.output + assert "Missing argument 'name'" in result.output def test_2(): diff --git a/tests/test_tutorial/test_first_steps/test_tutorial003.py b/tests/test_tutorial/test_first_steps/test_tutorial003.py index e92f23521e..5c5ddb39cf 100644 --- a/tests/test_tutorial/test_first_steps/test_tutorial003.py +++ b/tests/test_tutorial/test_first_steps/test_tutorial003.py @@ -15,7 +15,7 @@ def test_1(): result = runner.invoke(app, ["Camila"]) assert result.exit_code != 0 - assert "Missing argument 'LASTNAME'" in result.output + assert "Missing argument 'lastname'" in result.output def test_2(): diff --git a/tests/test_tutorial/test_first_steps/test_tutorial004.py b/tests/test_tutorial/test_first_steps/test_tutorial004.py index 6ac326f074..0232605f97 100644 --- a/tests/test_tutorial/test_first_steps/test_tutorial004.py +++ b/tests/test_tutorial/test_first_steps/test_tutorial004.py @@ -16,9 +16,9 @@ def test_help(): result = runner.invoke(app, ["--help"]) assert result.exit_code == 0 assert "Arguments" in result.output - assert "NAME" in result.output + assert "{name}" in result.output assert "[required]" in result.output - assert "LASTNAME" in result.output + assert "{lastname}" in result.output assert "[required]" in result.output assert "--formal" in result.output assert "--no-formal" in result.output diff --git a/tests/test_tutorial/test_first_steps/test_tutorial005.py b/tests/test_tutorial/test_first_steps/test_tutorial005.py index 87ce389410..48c80573f1 100644 --- a/tests/test_tutorial/test_first_steps/test_tutorial005.py +++ b/tests/test_tutorial/test_first_steps/test_tutorial005.py @@ -16,10 +16,10 @@ def test_help(): result = runner.invoke(app, ["--help"]) assert result.exit_code == 0 assert "Arguments" in result.output - assert "NAME" in result.output + assert "{name}" in result.output assert "[required]" in result.output assert "--lastname" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "--formal" in result.output assert "--no-formal" in result.output diff --git a/tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py b/tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py index 0fd8ed8f33..c31fabce69 100644 --- a/tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py +++ b/tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py @@ -27,7 +27,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "[OPTIONS] [NAMES]..." in result.output + assert "[OPTIONS] [names]..." in result.output assert "Arguments" in result.output assert "[default: Harry, Hermione, Ron]" in result.output diff --git a/tests/test_tutorial/test_options/test_help/test_tutorial003.py b/tests/test_tutorial/test_options/test_help/test_tutorial003.py index de99469dfa..4bb1cc10a9 100644 --- a/tests/test_tutorial/test_options/test_help/test_tutorial003.py +++ b/tests/test_tutorial/test_options/test_help/test_tutorial003.py @@ -32,7 +32,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--fullname" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "[default: Wade Wilson]" not in result.output diff --git a/tests/test_tutorial/test_options/test_help/test_tutorial004.py b/tests/test_tutorial/test_options/test_help/test_tutorial004.py index 22f902197b..5936ebca97 100644 --- a/tests/test_tutorial/test_options/test_help/test_tutorial004.py +++ b/tests/test_tutorial/test_options/test_help/test_tutorial004.py @@ -34,7 +34,7 @@ def test_help(monkeypatch, mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--fullname" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "[default: (Deadpoolio the amazing's name)]" in result.output diff --git a/tests/test_tutorial/test_options/test_name/test_tutorial001.py b/tests/test_tutorial/test_options/test_name/test_tutorial001.py index 1c4f2a7cf0..d375a92bfd 100644 --- a/tests/test_tutorial/test_options/test_name/test_tutorial001.py +++ b/tests/test_tutorial/test_options/test_name/test_tutorial001.py @@ -26,7 +26,7 @@ def test_option_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--name" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "--user-name" not in result.output diff --git a/tests/test_tutorial/test_options/test_name/test_tutorial002.py b/tests/test_tutorial/test_options/test_name/test_tutorial002.py index ac9b3db6f1..9e0dcb4892 100644 --- a/tests/test_tutorial/test_options/test_name/test_tutorial002.py +++ b/tests/test_tutorial/test_options/test_name/test_tutorial002.py @@ -27,7 +27,7 @@ def test_option_help(mod: ModuleType): assert result.exit_code == 0 assert "-n" in result.output assert "--name" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "--user-name" not in result.output diff --git a/tests/test_tutorial/test_options/test_name/test_tutorial003.py b/tests/test_tutorial/test_options/test_name/test_tutorial003.py index 0503b410af..e20ca92a63 100644 --- a/tests/test_tutorial/test_options/test_name/test_tutorial003.py +++ b/tests/test_tutorial/test_options/test_name/test_tutorial003.py @@ -26,7 +26,7 @@ def test_option_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "-n" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "--user-name" not in result.output assert "--name" not in result.output diff --git a/tests/test_tutorial/test_options/test_name/test_tutorial004.py b/tests/test_tutorial/test_options/test_name/test_tutorial004.py index f200021042..862890b9c7 100644 --- a/tests/test_tutorial/test_options/test_name/test_tutorial004.py +++ b/tests/test_tutorial/test_options/test_name/test_tutorial004.py @@ -27,7 +27,7 @@ def test_option_help(mod: ModuleType): assert result.exit_code == 0 assert "-n" in result.output assert "--user-name" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "--name" not in result.output diff --git a/tests/test_tutorial/test_options/test_name/test_tutorial005.py b/tests/test_tutorial/test_options/test_name/test_tutorial005.py index 492a0fc4ef..520073b98e 100644 --- a/tests/test_tutorial/test_options/test_name/test_tutorial005.py +++ b/tests/test_tutorial/test_options/test_name/test_tutorial005.py @@ -27,7 +27,7 @@ def test_option_help(mod: ModuleType): assert result.exit_code == 0 assert "-n" in result.output assert "--name" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "-f" in result.output assert "--formal" in result.output diff --git a/tests/test_tutorial/test_options/test_password/test_tutorial001.py b/tests/test_tutorial/test_options/test_password/test_tutorial001.py index 4aca1c0bd8..8374a497a3 100644 --- a/tests/test_tutorial/test_options/test_password/test_tutorial001.py +++ b/tests/test_tutorial/test_options/test_password/test_tutorial001.py @@ -44,7 +44,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 output_without_double_spaces = strip_double_spaces(result.output) - assert "--email TEXT [required]" in output_without_double_spaces + assert "--email [required]" in output_without_double_spaces def test_script(mod: ModuleType): diff --git a/tests/test_tutorial/test_options/test_password/test_tutorial002.py b/tests/test_tutorial/test_options/test_password/test_tutorial002.py index 08d43ff87e..4b63dbc20c 100644 --- a/tests/test_tutorial/test_options/test_password/test_tutorial002.py +++ b/tests/test_tutorial/test_options/test_password/test_tutorial002.py @@ -48,7 +48,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 output_without_double_spaces = strip_double_spaces(result.output) - assert "--password TEXT [required]" in output_without_double_spaces + assert "--password [required]" in output_without_double_spaces def test_script(mod: ModuleType): diff --git a/tests/test_tutorial/test_options/test_prompt/test_tutorial001.py b/tests/test_tutorial/test_options/test_prompt/test_tutorial001.py index 1236f33e57..c0d1e5770c 100644 --- a/tests/test_tutorial/test_options/test_prompt/test_tutorial001.py +++ b/tests/test_tutorial/test_options/test_prompt/test_tutorial001.py @@ -39,7 +39,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--lastname" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "[required]" in result.output diff --git a/tests/test_tutorial/test_options/test_prompt/test_tutorial002.py b/tests/test_tutorial/test_options/test_prompt/test_tutorial002.py index 0947a5e77e..42def22bd6 100644 --- a/tests/test_tutorial/test_options/test_prompt/test_tutorial002.py +++ b/tests/test_tutorial/test_options/test_prompt/test_tutorial002.py @@ -39,7 +39,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--lastname" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "[required]" in result.output diff --git a/tests/test_tutorial/test_options/test_prompt/test_tutorial003.py b/tests/test_tutorial/test_options/test_prompt/test_tutorial003.py index 6016dc4acf..daefde09fa 100644 --- a/tests/test_tutorial/test_options/test_prompt/test_tutorial003.py +++ b/tests/test_tutorial/test_options/test_prompt/test_tutorial003.py @@ -48,7 +48,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--project-name" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "[required]" in result.output diff --git a/tests/test_tutorial/test_options/test_required/test_tutorial001_tutorial002.py b/tests/test_tutorial/test_options/test_required/test_tutorial001_tutorial002.py index 72ad6e04cd..5003c80ae3 100644 --- a/tests/test_tutorial/test_options/test_required/test_tutorial001_tutorial002.py +++ b/tests/test_tutorial/test_options/test_required/test_tutorial001_tutorial002.py @@ -41,7 +41,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--lastname" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "[required]" in result.output @@ -50,7 +50,7 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--lastname" in result.output - assert "TEXT" in result.output + assert "" in result.output assert "[required]" in result.output diff --git a/tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py b/tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py index eea63c5a8b..ba9ac4f5e9 100644 --- a/tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py +++ b/tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py @@ -20,7 +20,7 @@ def test_type_repr(): def test_help(): result = runner.invoke(app, ["--help"]) assert result.exit_code == 0 - assert "[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output + assert "<%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S>" in result.output def test_main(): diff --git a/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py b/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py index 6ec636d7ec..a27d32f1bb 100644 --- a/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py +++ b/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py @@ -13,7 +13,7 @@ def test_help(): result = runner.invoke(app, ["--help"]) assert result.exit_code == 0 assert "--network" in result.output - assert "[simple|conv|lstm]" in result.output + assert "" in result.output assert "default: simple" in result.output diff --git a/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial003.py b/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial003.py index d6c0e532c9..0bc6453dba 100644 --- a/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial003.py +++ b/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial003.py @@ -26,7 +26,7 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--groceries" in result.output - assert "[Eggs|Bacon|Cheese]" in result.output + assert "" in result.output assert "default: Eggs, Cheese" in result.output diff --git a/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial004.py b/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial004.py index 84f0eb3b16..0791fab333 100644 --- a/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial004.py +++ b/tests/test_tutorial/test_parameter_types/test_enum/test_tutorial004.py @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType: def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 - assert "--network [simple|conv|lstm]" in result.output.replace(" ", "") + assert "--network " in result.output.replace(" ", "") def test_main(mod): diff --git a/tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py b/tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py index ee0daa9f06..196e5b10b6 100644 --- a/tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py +++ b/tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py @@ -24,9 +24,9 @@ def test_help(): result = runner.invoke(app, ["--help"]) assert result.exit_code == 0 assert "--age" in result.output - assert "INTEGER" in result.output + assert "" in result.output assert "--height-meters" in result.output - assert "FLOAT" in result.output + assert "" in result.output def test_params(): diff --git a/tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py b/tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py index ffe3ad09a0..177ea43764 100644 --- a/tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py +++ b/tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py @@ -41,9 +41,9 @@ def test_help(mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--age" in result.output - assert "INTEGER RANGE" in result.output + assert "int range" in result.output assert "--score" in result.output - assert "FLOAT RANGE" in result.output + assert "float range" in result.output def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType): @@ -51,9 +51,9 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType): result = runner.invoke(mod.app, ["--help"]) assert result.exit_code == 0 assert "--age" in result.output - assert "INTEGER RANGE" in result.output + assert "int range" in result.output assert "--score" in result.output - assert "FLOAT RANGE" in result.output + assert "float range" in result.output def test_params(mod: ModuleType): diff --git a/tests/test_tutorial/test_typer_app/test_tutorial001.py b/tests/test_tutorial/test_typer_app/test_tutorial001.py index a951fe1881..175841b304 100644 --- a/tests/test_tutorial/test_typer_app/test_tutorial001.py +++ b/tests/test_tutorial/test_typer_app/test_tutorial001.py @@ -13,7 +13,7 @@ def test_no_arg(): result = runner.invoke(app) assert result.exit_code != 0 - assert "Missing argument 'NAME'." in result.output + assert "Missing argument 'name'." in result.output def test_arg(): diff --git a/tests/test_types.py b/tests/test_types.py index db6dae08da..aa97c3ca68 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -93,11 +93,11 @@ def test_enum_choice_repr() -> None: def test_enum_choice_help() -> None: result = runner.invoke(app, ["hello-argument", "--help"]) assert result.exit_code == 0 - assert "{rick|morty}" in result.output + assert "" in result.output result = runner.invoke(app, ["hello-option", "--help"]) assert result.exit_code == 0 - assert "[rick|morty]" in result.output + assert "" in result.output result = runner.invoke(app, ["hello-no-choices", "--help"]) assert result.exit_code == 0 From fc37d3af0bee40b81f3d307deda033f194b7b7f9 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 11:12:15 +0200 Subject: [PATCH 2/9] remove upper --- typer/_click/core.py | 2 +- typer/_types.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/typer/_click/core.py b/typer/_click/core.py index 580b558b9f..6f039265ce 100644 --- a/typer/_click/core.py +++ b/typer/_click/core.py @@ -885,7 +885,7 @@ def make_metavar(self, ctx: Context) -> str: metavar = self.type.get_metavar(param=self, ctx=ctx) if metavar is None: - metavar = self.type.name.upper() + metavar = self.type.name if self.nargs != 1: metavar += "..." diff --git a/typer/_types.py b/typer/_types.py index 09b38afb3f..356e92e762 100644 --- a/typer/_types.py +++ b/typer/_types.py @@ -50,7 +50,7 @@ def normalize_choice( def get_metavar(self, param: _click.Parameter, ctx: _click.Context) -> str | None: if param.param_type_name == "option" and not param.show_choices: # type: ignore choice_metavars = [ - types.convert_type(type(choice)).name.upper() for choice in self.choices + types.convert_type(type(choice)).name for choice in self.choices ] choices_str = "|".join([*dict.fromkeys(choice_metavars)]) else: From a3e01362a49735701264d775bc28741fc834d780 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 11:13:13 +0200 Subject: [PATCH 3/9] unify type names to Python types --- typer/_click/types.py | 6 +++--- typer/core.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/typer/_click/types.py b/typer/_click/types.py index 5ccf15fe1b..3375363002 100644 --- a/typer/_click/types.py +++ b/typer/_click/types.py @@ -142,7 +142,7 @@ def convert( class StringParamType(ParamType): - name = "text" + name = "str" def convert( self, value: Any, param: Union["Parameter", None], ctx: Union["Context", None] @@ -310,7 +310,7 @@ def __repr__(self) -> str: class IntParamType(_NumberParamTypeBase): - name = "integer" + name = "int" _number_class = int def __repr__(self) -> str: @@ -328,7 +328,7 @@ class IntRange(_NumberRangeBase, IntParamType): boundary instead of failing. """ - name = "integer range" + name = "int range" def _clamp( # type: ignore self, bound: int, dir: Literal[1, -1], open: bool diff --git a/typer/core.py b/typer/core.py index 6868ab4355..e1339b8d40 100644 --- a/typer/core.py +++ b/typer/core.py @@ -303,7 +303,7 @@ def human_readable_name(self) -> str: if self.metavar is not None: return self.metavar assert self.name is not None, "self.name or self.metavar should be set" - return self.name.upper() + return self.name def _get_default_string( self, @@ -388,7 +388,7 @@ def make_metavar(self, ctx: _click.Context) -> str: if not self.required and not var.startswith("["): var = f"[{var}]" return var - var = (self.name or "").upper() + var = self.name or "" if not self.required: var = f"[{var}]" type_var = self.type.get_metavar(self, ctx=ctx) From 121c30713701cbac851964698e365c177c73e498 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 11:13:31 +0200 Subject: [PATCH 4/9] choices with <> --- typer/_click/types.py | 2 +- typer/_types.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/typer/_click/types.py b/typer/_click/types.py index 3375363002..f49244c6c5 100644 --- a/typer/_click/types.py +++ b/typer/_click/types.py @@ -193,7 +193,7 @@ def __init__(self, formats: Sequence[str] | None = None): ] def get_metavar(self, param: "Parameter", ctx: "Context") -> str | None: - return f"[{'|'.join(self.formats)}]" + return f"<{'|'.join(self.formats)}>" def _try_to_convert_date(self, value: Any, format: str) -> datetime | None: try: diff --git a/typer/_types.py b/typer/_types.py index 356e92e762..26086fb270 100644 --- a/typer/_types.py +++ b/typer/_types.py @@ -58,12 +58,8 @@ def get_metavar(self, param: _click.Parameter, ctx: _click.Context) -> str | Non [str(i) for i in self._normalized_mapping(ctx=ctx).values()] ) - # Use curly braces to indicate a required argument. - if param.required and param.param_type_name == "argument": - return f"{{{choices_str}}}" - - # Use square braces to indicate an option or optional argument. - return f"[{choices_str}]" + # Use square braces as it's a type. + return f"<{choices_str}>" def get_missing_message( self, param: _click.Parameter, ctx: _click.Context | None From bb1969361347695aa26385829bde9f58fc04fcd0 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 15:02:02 +0200 Subject: [PATCH 5/9] add {} when argument is required --- typer/core.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typer/core.py b/typer/core.py index e1339b8d40..821181206d 100644 --- a/typer/core.py +++ b/typer/core.py @@ -387,10 +387,12 @@ def make_metavar(self, ctx: _click.Context) -> str: var = self.metavar if not self.required and not var.startswith("["): var = f"[{var}]" - return var + return f"{{{var}}}" var = self.name or "" if not self.required: var = f"[{var}]" + else: + var = f"{{{var}}}" type_var = self.type.get_metavar(self, ctx=ctx) if type_var: var += f":{type_var}" From d9c5943837241c618780090eb42df1e082e48b61 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 15:12:30 +0200 Subject: [PATCH 6/9] add <> around the metavar type --- typer/_click/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typer/_click/core.py b/typer/_click/core.py index 6f039265ce..d7bdf77099 100644 --- a/typer/_click/core.py +++ b/typer/_click/core.py @@ -885,7 +885,7 @@ def make_metavar(self, ctx: Context) -> str: metavar = self.type.get_metavar(param=self, ctx=ctx) if metavar is None: - metavar = self.type.name + metavar = f"<{self.type.name}>" if self.nargs != 1: metavar += "..." From 71861611704a7f65190349fb2e181a2f84f2702e Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 15:39:45 +0200 Subject: [PATCH 7/9] avoid lowercasing the parameters at declaration --- tests/test_core.py | 2 +- typer/core.py | 4 ++-- typer/main.py | 13 ++++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index c3920ab883..32a9aeafd1 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -25,7 +25,7 @@ def main( command = typer.main.get_command(app) params = {param.name: param for param in command.params} - assert params["my_arg_1"].human_readable_name == "MY_ARG_1" + assert params["my_arg_1"].human_readable_name == "my_arg_1" assert params["my_arg_2"].human_readable_name == "META_ARG" assert params["my_opt"].human_readable_name == "my_opt" diff --git a/typer/core.py b/typer/core.py index 821181206d..2314ad501c 100644 --- a/typer/core.py +++ b/typer/core.py @@ -412,7 +412,7 @@ def _parse_decls( raise TypeError("Argument is marked as exposed, but does not have a name.") if len(decls) == 1: name = arg = decls[0] - name = name.replace("-", "_").lower() + name = name.replace("-", "_") else: raise TypeError( "Arguments take exactly one parameter declaration, got" @@ -577,7 +577,7 @@ def _parse_decls( if name is None and possible_names: possible_names.sort(key=lambda x: -len(x[0])) # group long options first - name = possible_names[0][1].replace("-", "_").lower() + name = possible_names[0][1].replace("-", "_") if not name.isidentifier(): name = None diff --git a/typer/main.py b/typer/main.py index a825c1b14e..700648da66 100644 --- a/typer/main.py +++ b/typer/main.py @@ -1361,6 +1361,15 @@ def get_command_name(name: str) -> str: return name.lower().replace("_", "-") +def get_default_option_flag_name(name: str, metavar: str | None) -> str: + flag_name = name.replace("_", "-") + if metavar is not None: + meta_flag = metavar.replace("_", "-") + if meta_flag.lower() == flag_name.lower(): + return meta_flag + return flag_name + + def get_params_convertors_ctx_param_name_from_function( callback: Callable[..., Any] | None, ) -> tuple[list[TyperArgument | TyperOption], dict[str, Any], str | None]: @@ -1699,7 +1708,9 @@ def get_click_param( # Click doesn't accept a flag of type bool, only None, and then it sets it # to bool internally parameter_type = None - default_option_name = get_command_name(param.name) + default_option_name = get_default_option_flag_name( + param.name, parameter_info.metavar + ) if is_flag: default_option_declaration = ( f"--{default_option_name}/--no-{default_option_name}" From d59858af7c56644f36296ca509845ee99ca2bdd3 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 15:44:51 +0200 Subject: [PATCH 8/9] avoid two types of brackets --- typer/core.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/typer/core.py b/typer/core.py index 2314ad501c..4688d99c04 100644 --- a/typer/core.py +++ b/typer/core.py @@ -385,8 +385,10 @@ def make_metavar(self, ctx: _click.Context) -> str: # to include Argument name if self.metavar is not None: var = self.metavar - if not self.required and not var.startswith("["): - var = f"[{var}]" + if var.startswith("["): + return var + if not self.required: + return f"[{var}]" return f"{{{var}}}" var = self.name or "" if not self.required: From c0c90c9488157d43175d11430a0b89ed4ef1e90c Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sat, 27 Jun 2026 15:56:40 +0200 Subject: [PATCH 9/9] fix arg display in help --- typer/rich_utils.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/typer/rich_utils.py b/typer/rich_utils.py index de68f60644..adb76828c4 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -370,13 +370,18 @@ def _print_options_panel( metavar_type = None metavar_str = param.make_metavar(ctx=ctx) if isinstance(param, TyperArgument): - # TODO: revise this legacy behaviour of keeping argument names lowercased for Rich formatting - if param.metavar is None and param.name: - metavar_name = metavar_str.replace(param.name.upper(), param.name) + if param.metavar is not None: + metavar_name = param.metavar else: - metavar_name = metavar_str + metavar_name = param.name or "" + if not param.required: + metavar_name = f"[{metavar_name}]" if isinstance(param, TyperOption): metavar_type = metavar_str + elif isinstance(param, TyperArgument): + metavar_type = param.type.get_metavar(param=param, ctx=ctx) + if metavar_type is None: + metavar_type = f"<{param.type.name}>" for opt_str in param.opts: if "--" in opt_str: @@ -399,10 +404,6 @@ def _print_options_panel( # Fetch type if metavar_type and metavar_type != "BOOLEAN": types_data.append(metavar_type) - else: - type_str = param.type.name.upper() - if type_str != "BOOLEAN": - types_data.append(type_str) # Range - from # https://github.com/pallets/click/blob/c63c70dabd3f86ca68678b4f00951f78f52d0270/src/click/core.py#L2698-L2706 # noqa: E501