-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add new base validator and base constraint classes #136
Conversation
These base classes takes additional parameters such as the schema object to allow the contraints to use non-primitive validators Create new base classes for validator and constraint remove dead code Move optional check into base validator
This pull request fixes 6 alerts when merging e179cda into d2d65eb - view on LGTM.com fixed alerts:
|
yamale/validators/constraints.py
Outdated
for k in value.keys(): | ||
if self.key.validate(k) != []: | ||
errors = schema._validate(self.key, k, DataPath(), strict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to change the name of the _validate function, I will fix it
This pull request fixes 6 alerts when merging 5965dc6 into d2d65eb - view on LGTM.com fixed alerts:
|
Welcome back @drmull :) FYI: This may take me a while to get to, it's a busy time over here. Sorry. |
Thanks!
No problem, I am in no rush :) |
Sorry for the long delay. I grabbed the example from #133, but I couldn't get your code to work with it. data:
schema:
This combination should fail validation. |
Hm, strange. I updated the test case to match the example but I get:
Do you use the PyYAML parser? Maybe the order of the elements can differ with different parsers and trigger the problem. I will take a closer look! |
Yeah, I'm using PyYaml 5.3.1. However, I'm beginning to think this isn't something we should support. Allowing for
Both PyYAML and ruamel fail to load such a document, but it's valid yaml. Instead, I think the correct course of action is to not allow the include validator for the
Other validators can be used to constrain the |
Yeah, I can agree with that. I will close this PR and we can reopen it if ruamel implements complex keys in the future 😁 |
Cool, and thanks for your willingness to always jump in! |
Add new base classes to validator and constraint that take additional arguments, such as schema, path etc. This allows constraints to use non-primitive validators and resolves issue #133
My initial intention was to pull out the logic for the non-primitive validators from the schema file and put them in each respective validator class but then I figured it would be a bit too drastic..