From a56751ee64ad93955cd09749dead518aeb1b70aa Mon Sep 17 00:00:00 2001 From: Weiduhuo <1281586535@qq.com> Date: Sun, 12 Nov 2023 16:50:58 +0800 Subject: [PATCH 1/2] ignore Seperator when calculating length of choices in select --- questionary/prompts/select.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/questionary/prompts/select.py b/questionary/prompts/select.py index d6d41c5d..0455e096 100644 --- a/questionary/prompts/select.py +++ b/questionary/prompts/select.py @@ -132,14 +132,18 @@ def select( if choices is None or len(choices) == 0: raise ValueError("A list of choices needs to be provided.") - if use_shortcuts and len(choices) > len(InquirerControl.SHORTCUT_KEYS): - raise ValueError( - "A list with shortcuts supports a maximum of {} " - "choices as this is the maximum number " - "of keyboard shortcuts that are available. You" - "provided {} choices!" - "".format(len(InquirerControl.SHORTCUT_KEYS), len(choices)) + if use_shortcuts: + real_len_of_choices = sum( + 1 for c in choices if not isinstance(c, Separator) ) + if real_len_of_choices > len(InquirerControl.SHORTCUT_KEYS): + raise ValueError( + "A list with shortcuts supports a maximum of {} " + "choices as this is the maximum number " + "of keyboard shortcuts that are available. You " + "provided {} choices!" + "".format(len(InquirerControl.SHORTCUT_KEYS), real_len_of_choices) + ) merged_style = merge_styles_default([style]) From 29300da83a991acdfaa6619fee1875d715f39c3c Mon Sep 17 00:00:00 2001 From: Kian Cross Date: Thu, 11 Jan 2024 03:59:01 +0000 Subject: [PATCH 2/2] Fix formatting --- questionary/prompts/select.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/questionary/prompts/select.py b/questionary/prompts/select.py index 0455e096..a9443061 100644 --- a/questionary/prompts/select.py +++ b/questionary/prompts/select.py @@ -133,9 +133,7 @@ def select( raise ValueError("A list of choices needs to be provided.") if use_shortcuts: - real_len_of_choices = sum( - 1 for c in choices if not isinstance(c, Separator) - ) + real_len_of_choices = sum(1 for c in choices if not isinstance(c, Separator)) if real_len_of_choices > len(InquirerControl.SHORTCUT_KEYS): raise ValueError( "A list with shortcuts supports a maximum of {} "