Pick no longer works with lists that contain a dictionary
gyang2300 opened this issue · 2 comments
After upgrading to the latest pick, the following doesn't work anymore. It used to work in the previous version.
This was tested on Mac Sonoma 14.4.1 / python 3.11.5 / pick 2.3.0
#!/usr/bin/env python3
from pick import pick
title = 'Please choose your favorite programming language: '
options = [{'Language':'Java'}, {'Language':'JavaScript'}, {'Language':'Python'}, {'Language':'PHP'}, {'Language':'C++'}, {'Language':'Erlang'}, {'Language':'Haskell'}]
option, index = pick(options, title)
print(option)
print(option["Language"])
print(index)
Hi @gyang2300, thanks for the report.
I can reproduce the issue with this code (most the same as you posted):
from pick import pick
options = [{'Language':'Java'}, {'Language':'JavaScript'}, {'Language':'Python'}, {'Language':'PHP'}, {'Language':'C++'}, {'Language':'Erlang'}, {'Language':'Haskell'}]
print(pick(options))
But I think this is a misuse because passing a list of dictionaries to pick is unexpected and weired. Since pick
has type hints, you can run mypy or pyright, and you will get these complaints:
a.py:5: error: Value of type variable "OPTION_T" of "pick" cannot be "Dict[str, str]" [type-var]
Found 1 error in 1 file (checked 1 source file)
Modern IDEs like pycharm and vscode will warn you.
However, this break is easy to fix and won't involve too much impact to the code base, so I'll fix it and release a new version.
See v2.3.1.