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

Added support for sets and frozensets #342

Merged
merged 1 commit into from
Jun 24, 2018

Conversation

svisser
Copy link
Collaborator

@svisser svisser commented Jun 23, 2018

Hi there, this is a proposed fix for #292.

The docstring was done slightly differently than the others as the behaviour differs in the Python shell between Python 2.7 and Python 3.1+ (set([42]) vs {42}):

>>> set([42])
set([42])
>>> set([42])
{42}

The raised Invalid exceptions aren't used to avoid the problem that sequences currently have:

Schema([int,str])([3.4])

results in voluptuous.error.MultipleInvalid: expected str @ data[0] (the error message can be considered true but also incomplete as int is also allowed).

I'm not sure how to solve this - this could perhaps be refined in a future pull request?

@coveralls
Copy link

coveralls commented Jun 24, 2018

Coverage Status

Coverage increased (+0.1%) to 95.366% when pulling 4d742e4 on svisser:feature/support_sets into 72411cd on alecthomas:master.

Copy link
Collaborator

@tusharmakkar08 tusharmakkar08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @svisser

Thanks for the PR. Can you add the inclusion of sets and frozensets in README.md as well?

Thanks

... validator(set(['a']))
"""
type_ = type(schema)
type_name = 'set' if type_ == set else 'frozenset'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be type_name = type_.__name__? That will also handle user-defined subclasses of set, etc.

@svisser svisser force-pushed the feature/support_sets branch from fb81f16 to 4d742e4 Compare June 24, 2018 13:44
@svisser
Copy link
Collaborator Author

svisser commented Jun 24, 2018

Thanks, I have updated the commit with the requested changes. If there are any more just let me know.

@tusharmakkar08 tusharmakkar08 merged commit 4b5cb5b into alecthomas:master Jun 24, 2018
@svisser svisser deleted the feature/support_sets branch June 25, 2018 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants