Skip to content

Instantly share code, notes, and snippets.

@cjw296
Last active April 21, 2016 17:19
Show Gist options
  • Save cjw296/6384d1e0e9d2a4d14085 to your computer and use it in GitHub Desktop.
Save cjw296/6384d1e0e9d2a4d14085 to your computer and use it in GitHub Desktop.
Voluptuous double validate trick
# schema as follows, currently:
>>> schema = Schema({'logging': {Required('file_level', default='info'): str,
... Required('console_level', default='info'): str}})
# this works as desired:
>>> schema({'logging': {'file_level': 'warning'}})
{'logging': {'file_level': 'warning', 'console_level': info'}}
# this doesn't:
>>> schema({}})
{}
# what's the recommended way to have this happen:
>>> schema({}})
{'logging': {'file_level': 'info', 'console_level': info'}}
@cjw296
Copy link
Author

cjw296 commented Oct 23, 2015

schema = Schema({Required('logging', default=PopulateWithDefaults({})): {Required('file_level', default='info'): str,
                              Required('console_level', default='info'): str}})

?

@cjw296
Copy link
Author

cjw296 commented Oct 23, 2015

schema = Schema({Required('logging', default=Populate({})): {
                                   Required('file_level', default='info'): str,
                                   Required('console_level', default='info'): str
}})

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