Skip to content

Implement nested schema support and validators compilation#318

Merged
alecthomas merged 2 commits intoalecthomas:masterfrom
jd:self
Dec 26, 2017
Merged

Implement nested schema support and validators compilation#318
alecthomas merged 2 commits intoalecthomas:masterfrom
jd:self

Conversation

@jd
Copy link
Copy Markdown
Contributor

@jd jd 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!

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

Fixes alecthomas#128
@jd jd changed the title Pull request for self Implement nested schema support and validators compilation Dec 22, 2017
@coveralls
Copy link
Copy Markdown

coveralls commented Dec 22, 2017

Coverage Status

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

Copy link
Copy Markdown
Owner

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

Thanks for this. Just one minor comment.

Comment thread voluptuous/validators.py

class Any(object):
class _WithSubValidators(object):
def __init__(self, *validators, **kwargs):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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
@jd
Copy link
Copy Markdown
Contributor Author

jd commented Dec 24, 2017

Add docstring for _WithSubValidators

@coveralls
Copy link
Copy Markdown

coveralls 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
@alecthomas
Copy link
Copy Markdown
Owner

Both of those changes are great, thanks!

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.
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.

3 participants