From 32ae2acd3474a57d2450ea849545b2e1258bf76a Mon Sep 17 00:00:00 2001 From: Keerthana Panyam Date: Mon, 18 May 2026 13:59:38 -0700 Subject: [PATCH] choice shell autocompletion to use normalize_choice() -fixes enum choice autocomplete showing "MyEnum.foo" instead of "foo" -changed shell_complete() to use normalize_choice() instead of simply converting choices to strings --- CHANGES.rst | 2 ++ src/click/types.py | 3 +-- tests/test_shell_completion.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3543009674..0af01f6476 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,8 @@ Version 8.4.1 Unreleased - Zsh completion scripts parse correctly on Windows. :issue:`3277` +- Shell completion of `Choice` `Enum` values produces a valid completion + result. :issue:`3015` Version 8.4.0 diff --git a/src/click/types.py b/src/click/types.py index 556f20f2b8..1ca3e9b5de 100644 --- a/src/click/types.py +++ b/src/click/types.py @@ -408,8 +408,7 @@ def shell_complete( """ from click.shell_completion import CompletionItem - str_choices = map(str, self.choices) - + str_choices = [self.normalize_choice(choice, ctx) for choice in self.choices] if self.case_sensitive: matched = (c for c in str_choices if c.startswith(incomplete)) else: diff --git a/tests/test_shell_completion.py b/tests/test_shell_completion.py index 23c5ff05c1..6d9a58305c 100644 --- a/tests/test_shell_completion.py +++ b/tests/test_shell_completion.py @@ -473,7 +473,8 @@ def complete(ctx, param, incomplete): assert result.output == "plain,a\nplain,b\n" -@pytest.mark.parametrize(("value", "expect"), [(False, ["Au", "al"]), (True, ["al"])]) +# case_sensitive=False normalizes values to lowercase, matching remains case insensitive +@pytest.mark.parametrize(("value", "expect"), [(False, ["au", "al"]), (True, ["al"])]) def test_choice_case_sensitive(value, expect): cli = Command( "cli",