-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
bpo-33731: Implement support for locale specific format (WIP) #8612
Conversation
Adds support for 'l' and 'L' which will format a string as per 'f' except that they will use locale specific grouping, separators, and decimal point. In the case of 'L' the LC_MONETARY values will be used.
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. When your account is ready, please add a comment in this pull request You can check yourself Thanks again for your contribution, we look forward to reviewing it! |
Compare the output of the 'l' and 'L' formats against the output of `locale.format_string()`. The locale data seems to differ between platforms, so testing against literals is challenging. (Other format tests are explicitly providing locale data, but that approach would fail to properly test my modifications.) Also added a test against literals for the en_US locale in the hopes that it's consistent across platforms.
I think I need some guidance on testing this correctly. I see that the existing I've run tests locally on both MacOS and Windows, and they pass on my local machine, but the Windows CI build is failing. I haven't yet tested a Linux build locally, for which I'll need to spin up another VM. Finally, since this requires changes to |
If I approve the changes, the patch can include |
I can certainly use the aforementioned parameter, but I feel that doing so doesn't really exercise the changes. This changes The use of 'l' and 'L' was the suggestion of Eric Smith in his comment on bpo-34311. The intention being 'l' for locale and 'L' for monetary locale, as this format would not be exclusively for the monetary context. At any rate, I'm certainly open to changing the letters being used. |
I don't feel strongly about |
I did a bit more looking around, and the Single UNIX Specification for
Thus, It appears that the C99 implementation provides no mechanism to use the values from |
Currently we're using uppercase to mean "print an uppercase exponent". So:
Here I'd expect 'F', even though 'F' doesn't really do anything:
libmpdec actually makes use of the regular convention:
Perhaps we can use a modifier like |
Upon further discussion and research it appears that we should be supporting grouping via the `'` modifier as per C99
This implements the `'` modifier in place of the thousands separator to enable locale specific grouping and decimal point.
I've now implemented this (for just I also see that those other two modifiers are documented in PEP 378 and PEP 515. Should I be writing this up as a PEP as well? |
Interesting. Without knowing about this PR, I whipped up something similar (#11405). Clearly there is a demand for this feature. |
@james-emerton Perhaps a mini-PEP that briefly lists the motivation and syntax alternatives (I still like This is just my opinion, @ericvsmith is the format-language expert. |
Also @steelman of course. |
I've sent an e-mail to python-ideas, however, I can't see it in the archive yet. |
Last I was working on this (months ago!) I started but never finished drafting a PEP. I've finished that off and added a bit about the alternative suggestions I've seen. |
@james-emerton Thanks, in the meantime Eric Smith has posted his preferred version here: https://mail.python.org/pipermail/python-ideas/2019-January/054837.html I now support that version. PEPs should probably be announced and discussed on python-ideas. |
I suggest to continue the discussion at https://bugs.python.org/issue35638 and on python-ideas, so I'm closing this one now (we can reopen as appropriate later). |
Adds support for 'l' and 'L' which will format a string as per 'f'
except that they will use locale specific grouping, separators, and
decimal point. In the case of 'L' the LC_MONETARY values will be used.
https://bugs.python.org/issue33731