Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format() does not support locales for 'n' presentation type #5181

Open
dchiquito opened this issue Feb 24, 2024 · 1 comment
Open

format() does not support locales for 'n' presentation type #5181

dchiquito opened this issue Feb 24, 2024 · 1 comment
Labels
C-compat A discrepancy between RustPython and CPython

Comments

@dchiquito
Copy link
Contributor

Feature

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:

  1. Make RustPython/Parser/format aware of libc::locale. This would involve adding a dependency on libc.
  2. 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

https://docs.python.org/3/library/string.html#formatspec, specifically the 'n' presentation type.

@dchiquito dchiquito added the C-compat A discrepancy between RustPython and CPython label Feb 24, 2024
@youknowone
Copy link
Member

If anyone interested in, this is a guideline PR: #4609

dchiquito added a commit to dchiquito/RustPython that referenced this issue Mar 10, 2024
kingiler pushed a commit to kingiler/RustPython that referenced this issue Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-compat A discrepancy between RustPython and CPython
Projects
None yet
Development

No branches or pull requests

2 participants