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
{{ message }}
Repository navigation
format() does not support locales for 'n' presentation type #5181
There are a number of options available for formatting integers using the format() API. The default is 'd'. There is a closely related alternative formatting 'n' which works the same, but uses the locale settings to insert the correct separators. For example, format(123456789, 'n') == '123,456,789' (I am in the US, so my locale specifies , instead of .).
The current implementation does not include the separator, and therefore test_locale in test_format.py is failing.
I see two ways forward:
Make RustPython/Parser/format aware of libc::locale. This would involve adding a dependency on libc.
In int.rs, get the locale info and pass it to rustpython_parse::FormatSpec. This would involve adding an alternative constructor to the RustPython/Parser/format FormatSpec that also accepts locale info.
Python Documentation or reference to CPython source code
format(..., "n") now follows the active locale's thousands separator and decimal point.
On current main, locale.setlocale(locale.LC_ALL, "en_US.UTF-8") gives format(1234567, "n") == "1,234,567" and format(1234.5, "n") == "1,234.5". With de_DE.UTF-8 it is "1.234.567" / "1.234,5". Lib/test/test_format.py::test_locale and Lib/test/test_types.pytest_*__format__locale no longer carry expectedFailure.
Activity
youknowone commentedon Feb 26, 2024
If anyone interested in, this is a guideline PR: #4609
Disable test_locale in test_format.py
youknowone commentedon Oct 7, 2026
format(..., "n")now follows the active locale's thousands separator and decimal point.On current main,
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")givesformat(1234567, "n") == "1,234,567"andformat(1234.5, "n") == "1,234.5". Withde_DE.UTF-8it is"1.234.567"/"1.234,5".Lib/test/test_format.py::test_localeandLib/test/test_types.pytest_*__format__localeno longer carryexpectedFailure.Closing as resolved. Duplicate tracking: #4613.
— commented by Grok 4.6