From 213db252086549962329fb1608028ee48143122a Mon Sep 17 00:00:00 2001 From: AN Long Date: Wed, 24 Apr 2024 19:30:21 +0800 Subject: [PATCH] Allow pick list with non `str` or `Options` types (#121) * Allow pick non list of str or Options * ignore mypy * fix typo in test --- src/pick/__init__.py | 2 +- tests/test_pick.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 335a28a..860b848 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -152,7 +152,7 @@ def draw(self, screen: "curses._CursesWindow") -> None: description_present = False for option in self.options: - if isinstance(option, str) or option.description is not None: + if not isinstance(option, Option) or option.description is not None: description_present = True break diff --git a/tests/test_pick.py b/tests/test_pick.py index 8903a7c..eb839ab 100644 --- a/tests/test_pick.py +++ b/tests/test_pick.py @@ -31,10 +31,18 @@ def test_get_lines(): def test_no_title(): options = ["option1", "option2", "option3"] picker = Picker(options) - lines, current_line = picker.get_lines() + _, current_line = picker.get_lines() assert current_line == 1 +def test_pick_list_of_non_str_and_option(): + # More details: https://github.com/aisk/pick/issues/120 + options = [{"key1": "value1"}, {"key2": "value2"}] + picker = Picker(options) # type: ignore + lines, _ = picker.get_lines() + assert lines == ["* {'key1': 'value1'}", " {'key2': 'value2'}"] + + def test_multi_select(): title = "Please choose an option: " options = ["option1", "option2", "option3"]