[Python-checkins] bpo-38536: locale: Remove trailing space in formatted currency (GH-16864)

Inada Naoki webhook-mailer at python.org
Sun Jan 19 22:46:00 EST 2020


https://github.com/python/cpython/commit/e96d954527aa376457451e32a9d75ae3ea9ab4bd
commit: e96d954527aa376457451e32a9d75ae3ea9ab4bd
branch: master
author: Inada Naoki <songofacandy at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-01-20T12:45:50+09:00
summary:

bpo-38536: locale: Remove trailing space in formatted currency (GH-16864)

files:
A Misc/NEWS.d/next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst
M Lib/locale.py
M Lib/test/test_locale.py

diff --git a/Lib/locale.py b/Lib/locale.py
index dd8a08524a018..1a4e9f694f309 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -279,6 +279,8 @@ def currency(val, symbol=True, grouping=False, international=False):
         if precedes:
             s = smb + (separated and ' ' or '') + s
         else:
+            if international and smb[-1] == ' ':
+                smb = smb[:-1]
             s = s + (separated and ' ' or '') + smb
 
     sign_pos = conv[val<0 and 'n_sign_posn' or 'p_sign_posn']
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index c5d8e269d6318..2863d200e25c2 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -334,8 +334,7 @@ def test_currency(self):
         euro = '\u20ac'
         self._test_currency(50000, "50000,00 " + euro)
         self._test_currency(50000, "50 000,00 " + euro, grouping=True)
-        # XXX is the trailing space a bug?
-        self._test_currency(50000, "50 000,00 EUR ",
+        self._test_currency(50000, "50 000,00 EUR",
             grouping=True, international=True)
 
 
diff --git a/Misc/NEWS.d/next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst b/Misc/NEWS.d/next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst
new file mode 100644
index 0000000000000..147d181cc7e14
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst
@@ -0,0 +1,2 @@
+Removes trailing space in formatted currency with `international=True` and a locale with symbol following value.
+E.g. `locale.currency(12.34, international=True)` returned `'12,34 EUR '` instead of `'12,34 EUR'`.



More information about the Python-checkins mailing list