From c67dc0361a865e45f31093c9b6007cbb389c5889 Mon Sep 17 00:00:00 2001 From: Weiduhuo <1281586535@qq.com> Date: Sun, 12 Nov 2023 16:50:58 +0800 Subject: [PATCH] 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 d6d41c5..e74614f 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( + 0 if isinstance(c, Separator) else 1 for c in choices ) + 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])