-
Notifications
You must be signed in to change notification settings - Fork 238
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
Normalising tuples support #271 #301
Normalising tuples support #271 #301
Conversation
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.
though i'm pretty sure that it is covered, i would be reassured if you tested that the items' order is maintained in the normalized result of a sequence.
cerberus/validator.py
Outdated
@@ -666,8 +666,11 @@ def __normalize_sequence(self, field, mapping, schema): | |||
document_crumb=field, schema_crumb=(field, 'schema'), | |||
schema=schema) | |||
result = validator.normalized(document, always_return_document=True) | |||
for i in result: | |||
mapping[field][i] = result[i] | |||
if len(result.values()) > 0: |
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.
is that test necessary? if results:
would be more idiomatic.
cerberus/validator.py
Outdated
for i in result: | ||
mapping[field][i] = result[i] | ||
if len(result.values()) > 0: | ||
if type(mapping[field]) is tuple: |
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.
that wouldn't work with subclasses of tuple
, therefore the isinstance
function is common to identify types.
nonetheless, it should be enough to create a new object of a particular type: mapping[field] = type(mapping[field])(result.values)
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.
mind-blowing for me
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.
don't get addicted or you'll find yourself using Python for the laundry. ;-)
oh, and for fixing pull requests i recommend to squash your commits (or rather fix) and then force-push your branch. |
Awesome comments. Will fix this. |
Add corrections according @funkyfuture recomendations (pyeve#301 (review))
c4ce74a
to
3ba595e
Compare
cerberus/validator.py
Outdated
@@ -666,8 +666,8 @@ def __normalize_sequence(self, field, mapping, schema): | |||
document_crumb=field, schema_crumb=(field, 'schema'), | |||
schema=schema) | |||
result = validator.normalized(document, always_return_document=True) | |||
for i in result: | |||
mapping[field][i] = result[i] | |||
if result: |
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.
with my previous comment i meant two things, sorry for being unclear:
- this expression is semantically identical to the previous version
- the expression shouldn't be needed at all, but i might be wrong with that assumption
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.
You are totally right. Sorry about that, and thank you for your guide and your time. 😄
8927fe6
to
d3ed9dc
Compare
i tested it against a more nasty sequence and still found it to work. seems that value views are sorted in all Python version, which i didn't expect. we could also use that type instantiation for the normalized mappings to maintain the input's type. |
Great. Should I do something else or can we consider this issue closed? |
i'd consider it solved. i'll make a follow-up for the mappings later. |
Thanks! |
Closes #271 |
No description provided.