You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function parse_decimal() from babel.numbers module is wise enough to handle spaces as a grouping symbol where non-breakable space \xa0 is expected. However, parse_number() does not reproduce the same logic.
Traceback (most recent call last):
File "/home/myuser/.pyenv/versions/3.11.2/lib/python3.11/site-packages/babel/numbers.py", line 1030, in parse_number
return int(string.replace(get_group_symbol(locale, numbering_system=numbering_system), ''))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal forint() with base 10: '1 099'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in<module>
File "/home/myuser/.pyenv/versions/3.11.2/lib/python3.11/site-packages/babel/numbers.py", line 1032, in parse_number
raise NumberFormatError(f"{string!r} is not a valid number") from ve
babel.numbers.NumberFormatError: '1 099' is not a valid number
Actual Results
parse_number() unreasonably fails while trying to parse number with spaces in locales where non-breakable space is used as a grouping symbol.
Expected Results
Space and non-breakable space should be considered the same while parsing numbers. Logic used in parse_decimal() function should be used in parse_number() as well.
I guess, parse_number() should also introduce strict argument as well as parse_decimal() does.
The text was updated successfully, but these errors were encountered:
donnillo
changed the title
Unexpected behaviour: parse_numbers() doesn't handle spaces as a grouping symbol, however, parse_decimal() does
Unexpected behaviour: parse_numbers() doesn't handle space as a grouping symbol, however, parse_decimal() does
Jan 25, 2024
Overview Description
Function
parse_decimal()
frombabel.numbers
module is wise enough to handle spaces as a grouping symbol where non-breakable space\xa0
is expected. However,parse_number()
does not reproduce the same logic.Steps to Reproduce
Decimal('1099')
Actual Results
parse_number()
unreasonably fails while trying to parse number with spaces in locales where non-breakable space is used as a grouping symbol.Expected Results
Space and non-breakable space should be considered the same while parsing numbers. Logic used in
parse_decimal()
function should be used inparse_number()
as well.Reproducibility
Python 3.11.2
WSL\Ubuntu
Babel 2.14.0
Additional Information
I guess,
parse_number()
should also introducestrict
argument as well asparse_decimal()
does.The text was updated successfully, but these errors were encountered: