text2num should raise ValueError instead of AssertionError
Closed this issue · 0 comments
millerdev commented
From the docs
>>> text2num('mille mille deux cents')
AssertionError
First, an error message would be helpful to know what went wrong.
Second, the use of AssertionError
here is a bad choice. An assertion error should only be raised if the program is internally inconsistent (has a bug). It should not be possible to cause an assertion error by supplying bad input (unless the program is internally inconsistent, and therefore is indicating it has a bug).
I think ValueError
would be a better choice in this case since the user supplied a bad value. This is the same as passing a bad value to the built in int
function:
>>> int("not a number")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'not a number'
text2num
can't do anything about bad values passed to it other than raise an error indicating that it got a bad value.