Skip to content
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

Merged
merged 1 commit into from Mar 21, 2017

Conversation

@elecay
Copy link
Contributor

elecay commented Mar 17, 2017

No description provided.

Copy link
Member

funkyfuture left a comment

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.

@@ -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:

This comment has been minimized.

Copy link
@funkyfuture

funkyfuture Mar 18, 2017

Member

is that test necessary? if results: would be more idiomatic.

for i in result:
mapping[field][i] = result[i]
if len(result.values()) > 0:
if type(mapping[field]) is tuple:

This comment has been minimized.

Copy link
@funkyfuture

funkyfuture Mar 18, 2017

Member

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)

This comment has been minimized.

Copy link
@elecay

elecay Mar 18, 2017

Author Contributor

mind-blowing for me

This comment has been minimized.

Copy link
@funkyfuture

funkyfuture Mar 18, 2017

Member

don't get addicted or you'll find yourself using Python for the laundry. ;-)

@funkyfuture
Copy link
Member

funkyfuture commented Mar 18, 2017

oh, and for fixing pull requests i recommend to squash your commits (or rather fix) and then force-push your branch.

@elecay
Copy link
Contributor Author

elecay commented Mar 18, 2017

Awesome comments. Will fix this.

elecay added a commit to elecay/cerberus that referenced this pull request Mar 18, 2017
Add corrections according @funkyfuture recomendations
(pyeve#301 (review))
@elecay elecay force-pushed the elecay:normalizing_tuples_support#271 branch from c4ce74a to 3ba595e Mar 18, 2017
@@ -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:

This comment has been minimized.

Copy link
@funkyfuture

funkyfuture Mar 18, 2017

Member

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

This comment has been minimized.

Copy link
@elecay

elecay Mar 18, 2017

Author Contributor

You are totally right. Sorry about that, and thank you for your guide and your time. 😄

@elecay elecay force-pushed the elecay:normalizing_tuples_support#271 branch from 8927fe6 to d3ed9dc Mar 18, 2017
@nicolaiarocci nicolaiarocci added this to the 1.2 milestone Mar 20, 2017
@funkyfuture
Copy link
Member

funkyfuture commented Mar 20, 2017

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.

@elecay
Copy link
Contributor Author

elecay commented Mar 20, 2017

Great. Should I do something else or can we consider this issue closed?

@funkyfuture
Copy link
Member

funkyfuture commented Mar 20, 2017

i'd consider it solved. i'll make a follow-up for the mappings later.

@nicolaiarocci nicolaiarocci merged commit d3ed9dc into pyeve:master Mar 21, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
nicolaiarocci added a commit that referenced this pull request Mar 21, 2017
@nicolaiarocci
Copy link
Member

nicolaiarocci commented Mar 21, 2017

Thanks!

@nicolaiarocci
Copy link
Member

nicolaiarocci commented Mar 21, 2017

Closes #271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.