-
-
Notifications
You must be signed in to change notification settings - Fork 584
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
WIP: Support namedtuple validation #365
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,10 @@ _static | |
_templates | ||
|
||
TODO | ||
|
||
_trial_temp/ | ||
.eggs/ | ||
.tox/ | ||
build/ | ||
*.pyc | ||
*.egg-info |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ def create(meta_schema, validators=(), version=None, default_types=None): | |
if default_types is None: | ||
default_types = { | ||
u"array": list, u"boolean": bool, u"integer": int_types, | ||
u"null": type(None), u"number": numbers.Number, u"object": dict, | ||
u"null": type(None), u"number": numbers.Number, | ||
u"string": str_types, | ||
} | ||
|
||
|
@@ -135,7 +135,15 @@ def validate(self, *args, **kwargs): | |
raise error | ||
|
||
def is_type(self, instance, type): | ||
if type not in self._types: | ||
if type == u"object": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I'd rather widen the interface entirely here, rather than add complexity to the implementation. In draft 6 for example, for some reason we decided to make That use case, combined with yours, makes me think that what we'll need to do now is to actually move away from the idea that types are a mapping between names and classes to check via isinstance, and that we'll have to just have e.g. Does that sound reasonable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I'll see what I can do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure you're still interested in this, but if you are, @bsmithers is also poking about in this area in a branch of his. I think he's made some progress on the track above -- if you're interested might want to sync up with him. Gonna close this PR in the hope that we'll make enough progress there to resolve #364 but yeah this was super appreciated so definitely wouldn't mind some more hands if you are still pitching in. |
||
if isinstance(instance, dict): | ||
return True | ||
elif isinstance(instance, tuple) and \ | ||
hasattr(instance.__class__, '_fields'): | ||
return True | ||
else: | ||
return False | ||
elif type not in self._types: | ||
raise UnknownType(type, instance, self.schema) | ||
pytypes = self._types[type] | ||
|
||
|
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.
This is all stuff created when running
tox
locally.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.
The reason these aren't here already is because generally I'd recommend these go in your global git ignore, since they're things that should be ignored from all repos. E.g., mine is: https://github.com/Julian/dotfiles/blob/master/.config/git/ignore
But tbh I'm fine to merge it anyhow since I have had to explain ^ quite a few times so clearly at least some people are tripped up by it.