-
Notifications
You must be signed in to change notification settings - Fork 240
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
Make coerce
working within items
rule
#361
Conversation
36b3ea9
to
9d06a06
Compare
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.
thanks for this extension!
one thing isn't clear for me. the docs state regarding the items
rule:
The items will only be evaluated if the given iterable’s size matches the definition’s.
Is this also addressed in this normalization context?
i'd like to see a test that covers the case when a value in a document throws a ValueError
on coerce
. the handling seems covered. yet error handling deserves some regession tests, especially the error representations.
validator = self._get_child_validator( | ||
document_crumb=field, schema_crumb=(field, 'items'), | ||
schema=schema) | ||
value_type = type(mapping[field]) |
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.
why is type
being called here?
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.
Hi!
i'd like to see a test that covers the case when a value in a document throws a ValueError on coerce.
I've added tests for ValueError
and TypeError
.
why is
type
being called here?
I used __normalize_sequence
as a base. This line is added by commit eb24176 (Ensures container types are preserved in normalization). If tuple
passed instead list
, type will be preserved.
>>> schema = {'things': {'type': 'list', 'items': [{'coerce': int}, {'coerce': str}]}}
>>> validator = Validator(schema)
>>> validator.validate({'things': ['1', 2]})
True
>>> validator.document
{'things': [1, '2']}
>>> validator.validate({'things': ('1', 2)})
True
>>> validator.document
{'things': (1, '2')}
9d06a06
to
b1475fd
Compare
a'ight, cool.
ah, thanks for the reminder. ;-) just one thing, that should be a simple: when the number of fields in a sequence of a documnet is different from the amount of defined items in the relating |
Well... It seems I understand now why you asking :) So, is there alternative to Answer for your question is, yes, lengths must match :) |
now, i don't get your question. due to lack of context. but i'd recommend StackOverflow for such questions. regarding the length match; there's just a condition missing in line 688 to address this, right? oh, and one possibility isn't covered: when an |
@oev81 are you going to finalize this patch? |
@funkyfuture, sorry for not answering. I found the approach of coerce (conversion before validation) does not feet my task (conversion after validation, or conversion within validation). |
@nicolaiarocci would you re-open this pr and assign me to it? i'd complete this blind spot some day. |
Case example:
schema = {'things': {'type': 'list', 'items': [{'coerce': int}, {'coerce': str}]}}