Skip to content

With prompt, if no input is specified, the return value is not converted to the requested type - #1517

Merged
davidism merged 1 commit into
pallets:masterfrom
stgraham2000:master
Oct 14, 2020
Merged

davidism merged 1 commit into
pallets:masterfrom
stgraham2000:master

Conversation

@stgraham2000

Copy link
Copy Markdown

If the passed in default is a string but the type parameter is not a string then click should do its best to convert the default to the requested type.

This becomes an issue when using mypy with click. MyPy will complain if you pass anything but a string for the default. One option is to do a type ignore but that starts to pollute the code quickly if you have a lot of prompts that expect integer values. Fixing this also will prevent some accidental bugs where you use different types with your type option and your default. Click should do its best to honor the requested type.

@davidism davidism added the prompt Interactive input and confirmation label Aug 9, 2020
@davidism davidism added this to the 8.0.0 milestone Oct 14, 2020
@davidism

davidism commented Oct 14, 2020 •

Copy link
Copy Markdown
Member

Looks like there was already a special check for the Path type, but it doesn't seem like there was any reason to restrict it to that type, so I simplified it. It was probably because not all types were able to pass through a value that was already the correct type, but that was fixed in #1649 #1687.

@davidism
davidism merged commit 801a29f into pallets:master Oct 14, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

prompt Interactive input and confirmation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants