-
Notifications
You must be signed in to change notification settings - Fork 8
Protect custom type testers against None values #66
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
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 |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ def __init__(self, **kwargs): | |
| super(Time, self).__init__(**kwargs) | ||
|
|
||
| def cast(self, d): | ||
| if d is None: | ||
| return d | ||
| if re.match(r"^(?:[01]\d|2[0-3]|\d):[0-5]\d$", str(d)): | ||
| return Text().cast(d) | ||
| raise CastError('Can not parse value "%s" as time.' % d) | ||
|
|
@@ -36,6 +38,8 @@ def __init__(self): | |
| super(SirenSiret, self).__init__() | ||
|
|
||
| def cast(self, d): | ||
| if d is None: | ||
| return d | ||
| if is_valid_siret(d) or is_valid_siren(d): | ||
|
Member
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. These functions don't crash for non-string arguments?
Contributor
Author
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 think the tests cover this. And I'd say every value come as a string since it's a CSV and we're trying to guess types. |
||
| return Text().cast(d) | ||
| raise CastError('Can not parse value "%s" as a SIREN or SIRET.' % d) | ||
|
|
||
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 this needed? The next line casts to a string before trying to match the regex.
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.
tests fail w/o this so I guess so :-)