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

Emit warning when user passes string instead of list to OneOf #2074

Open
lafrech opened this issue Nov 25, 2022 · 2 comments
Open

Emit warning when user passes string instead of list to OneOf #2074

lafrech opened this issue Nov 25, 2022 · 2 comments

Comments

@lafrech
Copy link
Member

lafrech commented Nov 25, 2022

I just got caught.

I wrote

    validate=validate.OneOf("one", "two")

instead of

    validate=validate.OneOf(["one", "two"])

"one" would pass because "one" in "one" is True.

It might save users trouble if we emitted a warning when a string is passed instead of a non-string iterable.

In practice, it only affects lists made of two elements (or one but users would use Equal), so no big deal.

@deckar01
Copy link
Member

deckar01 commented Dec 6, 2022

I suppose there could be users passing single character sets as a string intentionally. It wouldn't be too much trouble to wrap them a list() call to silence a warning though.

@lafrech
Copy link
Member Author

lafrech commented Dec 11, 2022

Passing a single character should be done with Equal anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants