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

don't type cast when getting default #2085

davidism opened this issue Oct 7, 2021 · 0 comments

don't type cast when getting default #2085

davidism opened this issue Oct 7, 2021 · 0 comments


Copy link

davidism commented Oct 7, 2021

Click 8 changed the processing pipeline in an effort to be more consistent. Part of that made fetching the default value happen in the same area of code as fetching the value from other sources, then processing whatever value was fetched. However, get_default still calls type_cast_value, which was a holdover from the previous code.

This causes default values to be type cast twice, once when fetching the default value, then again when processing the value. It also causes the default to be type cast when showing the help text, which can lead to unexpected output, such as the string representation of an open file object instead of the filename.

In general, custom parameter types should still be able to handle being passed a value of the correct type. This can still happen if the default is the correct type, or when prompting (which converts the value to the type for validation before returning), or when passing arguments to main() from Python instead of the command line.

Fetching the default value should behave more like the other source handled in consume_value. Env vars and context defaults are not type cast, so the default should not be either. This should prevent the most common source of issues with existing custom types (although they should still be updated to work as described above).

Related to:

There are still some other unexpected behaviors, such as type casting flag_value, but that will have to be handled separately.

@davidism davidism added this to the 8.0.2 milestone Oct 7, 2021
@davidism davidism self-assigned this Oct 7, 2021
@davidism davidism closed this as completed Oct 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

No branches or pull requests

1 participant