Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
@dchiquito

Description

@dchiquito

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions