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.
Steps to Reproduce
from babel.numbers import (
parse_number,
parse_decimal
)
parse_decimal('1 099', locale='ru', numbering_system='default') # OK
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 for int() 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.
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
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.