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

Assure choices are strings #1395

Closed
wants to merge 1 commit into from
Closed

Conversation

ssbarnea
Copy link

Fixes problem where the iterator may return different objects, making
choice fail when trying to use string specific methods.

Example:

    return '[%s]' % '|'.join(self.choices)
TypeError: sequence item 0: expected str instance, XXX found

Fixes: #591

Fixes problem where the iterator may return different objects, making
choice fail when trying to use string specific methods.

Example:

    return '[%s]' % '|'.join(self.choices)
TypeError: sequence item 0: expected str instance, XXX found

Fixes: pallets#591
@jcrotts
Copy link
Contributor

jcrotts commented Jun 5, 2020

Thanks for the PR! I'm not sure if we should convert to strings here. I think as a user I would prefer the error message over the implicit conversion.

@davidism
Copy link
Member

davidism commented Jun 6, 2020

The point about raising an error stands, but I'm also not sure I want to add more runtime type checking. Now that Pallets is Python 3.6+, typing should probably be handled by adding annotations throughout the library.

@davidism
Copy link
Member

Thanks for looking at this, but at this point other Pallets projects are adding annotations, which I want to prefer over runtime type checking. The docs already call out that all choices must be strings. On that point, this PR allows ints, which will still fail.

@davidism davidism closed this Aug 13, 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support data types other than string for click.Choice values
5 participants