Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent Breaking Change to Choice Api #88

Closed
BradenM opened this issue Nov 17, 2020 · 1 comment
Closed

Recent Breaking Change to Choice Api #88

BradenM opened this issue Nov 17, 2020 · 1 comment
Labels
Bug Something isn't working

Comments

@BradenM
Copy link

BradenM commented Nov 17, 2020

A breaking change was made to the Choice object api at some point between questionary versions 1.6.0 and 1.8.0 when specifying the value parameter.

Previously, in v1.6.0, the expected behavior was for the selected choice to return the provided value= "as is" with no modifications.

However, in v1.8.0, anything passed to value is now type cast as a string, leading to breaking changes for applications expecting the returned value to be of the same type originally passed in to the value parameter. (See BradenM/micropy-cli#184, the issue that led to finding this.)

Quick search through the commit history points to this commit: 604c112 from #14 as a likely culprit.

I'm not sure if Questionary follows semantic versioning or not, but if so that PR (if it is actually the culprit) probably should have bumped the project version up by a major version given that the change is not backwards compatible w/ existing projects using v1.6.0.

Questionary v1.6.0

Python 3.8.3 (default, May 22 2020, 23:45:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from questionary import Choice

In [2]: import questionary as prompt

In [3]: choices = [Choice("one", value=1)]

In [4]: prompt_ch = prompt.checkbox("Choose a value", choices=choices).ask()
? Choose a value  [one]

In [5]: prompt_ch
Out[5]: [1]

In [6]: type(prompt_ch[0])
Out[6]: int

In [7]: prompt.__version__
Out[7]: '1.6.0'

Questionary v1.8.0

Python 3.8.3 (default, May 22 2020, 23:45:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from questionary import Choice

In [2]: import questionary as prompt

In [3]: choices = [Choice("one", value=1)]

In [4]: prompt_ch = prompt.checkbox("Choose a value", choices=choices).ask()
? Choose a value  [one]

In [5]: prompt_ch
Out[5]: ['1']

In [6]: type(prompt_ch[0])
Out[6]: str

In [7]: prompt.__version__
Out[7]: '1.8.0'
@tmbo
Copy link
Owner

tmbo commented Nov 17, 2020

Thanks a lot for bringing this up, this seemed to have been a regression in 1.8.0. It wasn't an intentional change.

I've added a test for this as well as a fix. If the build passes, I'll tag a 1.8.1 release with a fix.

@tmbo tmbo added the Bug Something isn't working label Nov 17, 2020
BradenM added a commit to BradenM/micropy-cli that referenced this issue Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants