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

Implement nested schema support and validators compilation #318

Merged
merged 2 commits into from Dec 26, 2017

Conversation

@jd
Copy link
Contributor

commented Dec 22, 2017

This PR is made of 2 commits:

  • Allow to use nested schema that adds voluptuous.Self as a reference to the Schema being compiled.

  • Allow any validator to be compiled which allows to compile validators and implements that compilation on validators with subvalidators (and/or/someof) in order to avoid the subSchema creation. This solves the recursive voluptuous.Self case elegantly.

Hope you'll enjoy it!

Allow to use nested schema
This allows to refer to the current schema using voluptuous.Self and have
nested definitions.

Fixes #128

@jd jd changed the title Pull request for self Implement nested schema support and validators compilation Dec 22, 2017

@coveralls

This comment has been minimized.

Copy link

commented Dec 22, 2017

Coverage Status

Coverage decreased (-0.04%) to 95.382% when pulling 0d25e4a on jd:self into 1666a68 on alecthomas:master.

@alecthomas
Copy link
Owner

left a comment

Thanks for this. Just one minor comment.

@@ -181,7 +181,33 @@ def Boolean(v):
return bool(v)


class Any(object):
class _WithSubValidators(object):
def __init__(self, *validators, **kwargs):

This comment has been minimized.

Copy link
@alecthomas

alecthomas Dec 24, 2017

Owner

Please add a docstring here describing how this is intended to be used.

Allow any validator to be compiled
This allows any validator to be compiled by implementing the
__voluptuous_compile__ method.

This avoids having voluptuous.Any and voluptuous.All defining new Schema for
sub-validators: they can be compiled recursively using the same parent schema.

This solves the recursive Self case.

Fixes #18
@jd

This comment has been minimized.

Copy link
Contributor Author

commented Dec 24, 2017

Add docstring for _WithSubValidators

@jd jd force-pushed the jd:self branch from 0d25e4a to 975562b Dec 24, 2017

@coveralls

This comment has been minimized.

Copy link

commented Dec 24, 2017

Coverage Status

Coverage decreased (-0.04%) to 95.382% when pulling 975562b on jd:self into 1666a68 on alecthomas:master.

@alecthomas alecthomas merged commit 0dad58b into alecthomas:master Dec 26, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.04%) to 95.382%
Details
@alecthomas

This comment has been minimized.

Copy link
Owner

commented Dec 26, 2017

Both of those changes are great, thanks!

@balloob balloob referenced this pull request Feb 16, 2018

wip-sync pushed a commit to NetBSD/pkgsrc-wip that referenced this pull request Aug 13, 2019

py-voluptuous: Update to 0.11.7
Upstream changes are many minor improvements and bugfixes, plus

**Changes**

- [#378](alecthomas/voluptuous#378): Allow `extend()` of a `Schema` to return a subclass of a `Schema` as well.

**Changes**:

- [#349](alecthomas/voluptuous#349): Support Python 3.7.
- [#343](alecthomas/voluptuous#343): Drop support for Python 3.3.

**Changes**:

- [#293](alecthomas/voluptuous#293): Support Python 3.6.
- [#294](alecthomas/voluptuous#294): Drop support for Python 2.6, 3.1 and 3.2.
- [#318](alecthomas/voluptuous#318): Allow to use nested schema and allow any validator to be compiled.
- [#324](alecthomas/voluptuous#324):
  Default values MUST now pass validation just as any regular value. This is a backward incompatible change if a schema uses default values that don't pass validation against the specified schema.
- [#328](alecthomas/voluptuous#328):
  Modify `__lt__` in Marker class to allow comparison with non Marker objects, such as str and int.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.