[issue34311] locale.format() and locale.format_string() cast Decimals to float

2021-04-12 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:

I have merged the PR, thank you to Cédric for the PR, and thank you to Steve 
for his review.

--
resolution:  -> fixed
stage: commit review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2021-04-12 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:


New changeset e126547c070fbc080562abb08e16a2c93a8a805d by Cédric Krier in 
branch 'master':
bpo-34311: Add locale.localize (GH-15275)
https://github.com/python/cpython/commit/e126547c070fbc080562abb08e16a2c93a8a805d


--
nosy: +matrixise

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2021-04-12 Thread Stéphane Wirtel

Change by Stéphane Wirtel :


--
versions: +Python 3.10 -Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2020-01-11 Thread Steve Holden


Steve Holden  added the comment:

Verified. Methododology:

1. Copied test_localise.py from the PR into a master checkout.
2. Added a null locale.localize.
3. Verified that all new tests failed.

.. code-block::

  Ran 64 tests in 0.023s

  FAILED (errors=4, skipped=4)
  (base) blockhead:cpython sholden$ vi Lib/locale.py
  (base) blockhead:cpython sholden$ ./python.exe -m test.test_locale
  ...F...testing with ('tr_TR', 
'ISO8859-9') .testing with 'en_US.UTF-8'... .testing with 'en_US.UTF-8'... 
.testing with 'en_US.UTF-8'... .testing with 'en_US.UTF-8'... .testing with 
'en_US.UTF-8'... .testing with 'en_US.UTF-8'... .testing with 'en_US.UTF-8'... 
.testing with 'en_US.UTF-8'... F
  ==
  FAIL: test_localize_invalid_format (__main__.TestEnUSLocalize)
  --
  Traceback (most recent call last):
File "/Users/sholden/cpython/Lib/test/test_locale.py", line 613, in 
test_localize_invalid_format
  locale.localize('foo')
  AssertionError: ValueError not raised

  ==
  FAIL: test_localize (__main__.TestfrFRLocalize)
  --
  Traceback (most recent call last):
File "/Users/sholden/cpython/Lib/test/test_locale.py", line 625, in 
test_localize
  self._test_localize('5.00', '5,00')
File "/Users/sholden/cpython/Lib/test/test_locale.py", line 601, in 
_test_localize
  self.assertEqual(locale.localize(value, grouping=grouping), out)
  AssertionError: '5.00' != '5,00'
  - 5.00
  ?  ^
  + 5,00
  ?  ^


  --
  Ran 64 tests in 0.024s

  FAILED (failures=2, skipped=4)

4. Checked out cedk/locale_format branch.
5. Observed that all locale tests now pass.

Seems to me like this one should be good to go, so I've changed the stage to 
"commit review" and await the application of some core developer's commit bit.

--
nosy: +holdenweb
stage: patch review -> commit review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2020-01-10 Thread Cédric Krier

Cédric Krier  added the comment:

For me, the name was natural as it is the reverse operation of the existing 
delocalize method.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2020-01-09 Thread Inada Naoki


Inada Naoki  added the comment:

Does the name "locale.localize" have some origin?

I feel the name doesn't represent well about it is for formatting numeric based 
on LC_NUMERIC.

--
nosy: +inada.naoki

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2019-08-14 Thread Cédric Krier

Cédric Krier  added the comment:

I think we can solve this issue like I solved issue13918 by providing a 
locale.localize() method which does the formatting as locale.format_string does 
but using the already formatted string.

I created PR-15275 which implements it and also use the new format in 
locale.currency as it is highly probable that currency will be used with 
Decimal.

--
nosy: +ced

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2019-08-14 Thread Cédric Krier

Change by Cédric Krier :


--
pull_requests: +14997
pull_request: https://github.com/python/cpython/pull/15275

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2018-08-04 Thread James Emerton


James Emerton  added the comment:

It looks like a bot got a bit excited when I mentioned this issue in the PR for 
bpo-33731. I unlinked the PR but this issue still got flagged for review.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2018-08-04 Thread James Emerton


Change by James Emerton :


--
pull_requests:  -8166

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2018-08-04 Thread James Emerton


Change by James Emerton :


--
keywords: +patch
pull_requests: +8166
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2018-08-01 Thread James Emerton


James Emerton  added the comment:

Certainly adding another letter to the format spec would solve my issue and 
would in fact be somewhat preferable to using local.format directly.

I think this could be fixed in the locale module by transforming the format 
spec and using new-style formatting, but I'm not familiar enough with the 
corner cases to know if its practical to cover all the possible cases; 
particularly those coming from format_string().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2018-08-01 Thread Eric V. Smith


Eric V. Smith  added the comment:

Would my suggestion in #33731 of adding another letter in the format spec for 
float and decimal.Decimal solve your problem? I guess if you're using 
monetary=True you'd need two additional letters: like 'f' but locale aware, and 
like 'f' but locale aware and monetary=True.  Maybe 'l' and 'L' for these? In 
this case, there would be no changes to the locale module.

I don't see any good way of using new-style formatting without changing 
float.__format__ and decimal.Decimal.__format__.

--
components: +Interpreter Core
type:  -> enhancement
versions:  -Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2018-08-01 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34311] locale.format() and locale.format_string() cast Decimals to float

2018-08-01 Thread James Emerton


New submission from James Emerton :

We use locale.format('%.2f', x, True) to convert Decimal values to strings for 
display. Unfortunately, the locale module is using %-formatting to generate the 
initial string before applying locale specific formatting. As a result, any 
value which cannot be accurately represented as a float will produce incorrect 
results.

I've built some formatting that uses new-style string formatting (and some 
internal locale functions) which corrects the problem.

Unfortunately, making this change in the locale module would require converting 
the input format string to the new syntax, so '%.2f' would become '{:.2f}'.

See also #33731

--
components: Library (Lib)
messages: 322885
nosy: jemerton
priority: normal
severity: normal
status: open
title: locale.format() and locale.format_string() cast Decimals to float
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com