[pypy-commit] pypy default: argh, fix bug in locale-specific string formatting: the thousands separator was always '.' :-(

cfbolz pypy.commits at gmail.com
Fri Jan 31 08:11:56 EST 2020


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: 
Changeset: r98604:b6af70ef2dfb
Date: 2020-01-30 14:44 +0100
http://bitbucket.org/pypy/pypy/changeset/b6af70ef2dfb/

Log:	argh, fix bug in locale-specific string formatting: the thousands
	separator was always '.' :-(

diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -772,7 +772,7 @@
                     digits = self._upcase_string(digits)
                 out.append(digits)
             if spec.n_decimal:
-                out.append(self._lit(".")[0])
+                out.append(self._lit(self._loc_dec)[0])
             if spec.n_remainder:
                 out.append(num[to_remainder:])
             if spec.n_rpadding:
diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -389,6 +389,24 @@
         finally:
             locale.setlocale(locale.LC_NUMERIC, 'C')
 
+    def test_locale_german(self):
+        import locale
+        for name in ['de_DE', 'de_DE.utf8']:
+            try:
+                locale.setlocale(locale.LC_NUMERIC, name)
+                break
+            except locale.Error:
+                pass
+        else:
+            skip("no german locale")
+        x = 1234.567890
+        try:
+            assert locale.format('%g', x, grouping=True) == '1.234,57'
+            assert format(x, 'n') == '1.234,57'
+            assert format(12345678901234, 'n') == '12.345.678.901.234'
+        finally:
+            locale.setlocale(locale.LC_NUMERIC, 'C')
+
     def test_dont_switch_to_g(self):
         skip("must fix when float formatting is figured out")
         assert len(format(1.1234e90, "f")) == 98


More information about the pypy-commit mailing list