prompt-toolkit / prompt-toolkit/python-prompt-toolkit
mypy errors on examples from Dialog documentation
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
When using checkboxlist_dialog and radiolist_dialog from documentation, I get errors on values param.
how_to_reproduce.py
from __future__ import annotations
import prompt_toolkit.shortcuts as shortcuts
def select_checkbox() -> list[str]:
results_array: list[str] = shortcuts.checkboxlist_dialog(
title="CheckboxList dialog",
text="What would you like in your breakfast ?",
values=[
("eggs", "Eggs"),
("bacon", "Bacon"),
("croissants", "20 Croissants"),
("daily", "The breakfast of the day")
]
).run()
return results_array
def select_radio() -> str:
result: str = shortcuts.radiolist_dialog(
title="RadioList dialog",
text="Which breakfast would you like ?",
values=[
("breakfast1", "Eggs and beacon"),
("breakfast2", "French breakfast"),
("breakfast3", "Equestrian breakfast")
]
).run()
return result
x = select_checkbox()
print(x, type(x))
y = select_radio()
print(y, type(y))
Types generated can be seen with:
python how_to_reproduce.py
['bacon', 'croissants'] <class 'list'>
breakfast1 <class 'str'>
Mypy errors:
mypy how_to_reproduce.py
how_to_reproduce.py: note: In function "select_checkbox":
how_to_reproduce.py:5:32: error: Incompatible types in assignment (expression has type "List[<nothing>]", variable has type "List[str]") [assignment]
results_array: list[str] = shortcuts.checkboxlist_dialog(
^
how_to_reproduce.py:5:32: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
how_to_reproduce.py:5:32: note: Consider using "Sequence" instead, which is covariant
how_to_reproduce.py:8:16: error: Argument "values" to "checkboxlist_dialog" has incompatible type "List[Tuple[str, str]]"; expected
"Optional[List[Tuple[<nothing>, Union[str, MagicFormattedText, List[Union[Tuple[str, str], Tuple[str, str, Callable[[MouseEvent], None]]]], Callable[[], Any], None]]]]" [arg-type]
values=[
^
how_to_reproduce.py: note: In function "select_radio":
how_to_reproduce.py:21:16: error: Argument "values" to "radiolist_dialog" has incompatible type "List[Tuple[str, str]]"; expected
"Optional[List[Tuple[<nothing>, Union[str, MagicFormattedText, List[Union[Tuple[str, str], Tuple[str, str, Callable[[MouseEvent], None]]]], Callable[[], Any], None]]]]" [arg-type]
values=[
^
Found 3 errors in 1 file (checked 1 source file)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the documented checkboxlist_dialog and radiolist_dialog examples and run mypy on how_to_reproduce.py. Inspect the type signatures involved in their values parameters; done means the documented string tuples are accepted and the example passes mypy without the reported assignment or argument errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100