Skip to content

Fix Coerce validator to catch decimal.InvalidOperation#291

Merged
alecthomas merged 1 commit intomasterfrom
unknown repository
May 31, 2017
Merged

Fix Coerce validator to catch decimal.InvalidOperation#291
alecthomas merged 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented May 31, 2017

For some reason Python std lib has inconsistency in handling invalid values for numeric types:

>>> float('abc')
ValueError: could not convert string to float: abc
>>> int('abc')
ValueError: invalid literal for int() with base 10: 'abc'
>>> Fraction('abc')
ValueError: Invalid literal for Fraction: 'abc'
>>> Decimal('abc')
decimal.InvalidOperation: Invalid literal for Decimal: 'abc'

So this PR is to add InvalidOperation exception for Decimal type when using Coerce validator.

@coveralls
Copy link
Copy Markdown

coveralls commented May 31, 2017

Coverage Status

Coverage remained the same at 95.309% when pulling a30155c on geerk:master into 85b96b3 on alecthomas:master.

@alecthomas alecthomas merged commit 2392366 into alecthomas:master May 31, 2017
@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 1, 2017

@alecthomas Thanks!

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.

2 participants