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 elecay commented Mar 17, 2017

No description provided.

Copy link
Member

@funkyfuture funkyfuture left a 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.

@@ -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:
Copy link
Member

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.

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

@funkyfuture funkyfuture Mar 18, 2017

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind-blowing for me

Copy link
Member

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. ;-)

@funkyfuture
Copy link
Member

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 normalizing_tuples_support#271 branch from c4ce74a to 3ba595e Compare March 18, 2017 17:17
@@ -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:
Copy link
Member

@funkyfuture funkyfuture Mar 18, 2017

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

Copy link
Contributor Author

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. 😄

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

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

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
nicolaiarocci added a commit that referenced this pull request Mar 21, 2017
@nicolaiarocci
Copy link
Member

Thanks!

@nicolaiarocci
Copy link
Member

Closes #271

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

Successfully merging this pull request may close these issues.

3 participants