Implement nested schema support and validators compilation#318
Merged
alecthomas merged 2 commits intoalecthomas:masterfrom Dec 26, 2017
Merged
Implement nested schema support and validators compilation#318alecthomas merged 2 commits intoalecthomas:masterfrom
alecthomas merged 2 commits intoalecthomas:masterfrom
Conversation
This allows to refer to the current schema using voluptuous.Self and have nested definitions. Fixes alecthomas#128
alecthomas
requested changes
Dec 24, 2017
Owner
alecthomas
left a comment
There was a problem hiding this comment.
Thanks for this. Just one minor comment.
|
|
||
| class Any(object): | ||
| class _WithSubValidators(object): | ||
| def __init__(self, *validators, **kwargs): |
Owner
There was a problem hiding this comment.
Please add a docstring here describing how this is intended to be used.
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 alecthomas#18
Contributor
Author
|
Add docstring for _WithSubValidators |
Owner
|
Both of those changes are great, thanks! |
This was referenced Feb 15, 2018
This was referenced Feb 22, 2018
wip-sync
pushed a commit
to NetBSD/pkgsrc-wip
that referenced
this pull request
Aug 13, 2019
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is made of 2 commits:
Allow to use nested schema that adds
voluptuous.Selfas a reference to theSchemabeing 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 sub
Schemacreation. This solves the recursivevoluptuous.Selfcase elegantly.Hope you'll enjoy it!