From f7d98feecb91701dceaa0ff2574c854b321403f8 Mon Sep 17 00:00:00 2001 From: Matt Bibby Date: Tue, 11 Jul 2023 00:38:08 -0400 Subject: [PATCH] Revert inconsistent choice metavar formatting --- src/click/types.py | 16 +++------------- tests/test_options.py | 8 ++++---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/click/types.py b/src/click/types.py index 5c1e14442..595443b3f 100644 --- a/src/click/types.py +++ b/src/click/types.py @@ -259,23 +259,13 @@ def to_info_dict(self) -> dict[str, t.Any]: return info_dict def get_metavar(self, param: Parameter) -> str: - # Use choice ParamTypes if choices are hidden. if param.param_type_name == "option" and not param.show_choices: # type: ignore - _choices = [ + choice_metavars = [ convert_type(type(choice)).name.upper() for choice in self.choices ] + choices_str = "|".join([*dict.fromkeys(choice_metavars)]) else: - _choices = [str(i) for i in self.choices] - - # Dedupe choices - _choices = [*dict.fromkeys(_choices)] - - # Create choices_str - choices_str = "|".join(_choices) - - # Use no braces if single choice - if len(_choices) < 2: - return choices_str + choices_str = "|".join([str(i) for i in self.choices]) # Use curly braces to indicate a required argument. if param.required and param.param_type_name == "argument": diff --git a/tests/test_options.py b/tests/test_options.py index a3f13a03a..49df83bbd 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -931,10 +931,10 @@ def test_invalid_flag_combinations(runner, kwargs, message): @pytest.mark.parametrize( ("choices", "metavars"), [ - pytest.param(["foo", "bar"], "TEXT", id="text choices"), - pytest.param([1, 2], "INTEGER", id="int choices"), - pytest.param([1.0, 2.0], "FLOAT", id="float choices"), - pytest.param([True, False], "BOOLEAN", id="bool choices"), + pytest.param(["foo", "bar"], "[TEXT]", id="text choices"), + pytest.param([1, 2], "[INTEGER]", id="int choices"), + pytest.param([1.0, 2.0], "[FLOAT]", id="float choices"), + pytest.param([True, False], "[BOOLEAN]", id="bool choices"), pytest.param(["foo", 1], "[TEXT|INTEGER]", id="text/int choices"), ], )