From e99bcc56b668178d928e6e8a752d0f8d3dc9c25b Mon Sep 17 00:00:00 2001 From: Jonas Aschenbrenner Date: Sun, 20 Oct 2019 16:41:54 +0200 Subject: [PATCH 1/3] bpo-38536: Removes trailing space in formatted currency with international=True and symbol following value Validated that Ubuntu was affected and Windows 10 was not affected. Fix considers both cases. --- Lib/locale.py | 2 ++ Lib/test/test_locale.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/locale.py b/Lib/locale.py index dd8a08524a018e..1a4e9f694f3096 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 c5d8e269d63183..2863d200e25c2e 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) From 7f3525e341e96eedcd889bbfba549193bd10cbf4 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2019 20:24:52 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst 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 00000000000000..21a638c59ce30c --- /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(1345345345352.22, international=True)` returned `'1345345345352,22 EUR '` instead of `'1345345345352,22 EUR'` on Ubuntu. Windows 10 was not affected. \ No newline at end of file From ffcc4685e61234b69bd4de3fa520d9c05a7cdd7f Mon Sep 17 00:00:00 2001 From: Jonas Aschenbrenner Date: Sat, 18 Jan 2020 14:41:01 +0100 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst Co-Authored-By: Inada Naoki --- .../next/Library/2019-10-21-20-24-51.bpo-38536.beZ0Sk.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 21a638c59ce30c..147d181cc7e141 100644 --- 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 @@ -1,2 +1,2 @@ Removes trailing space in formatted currency with `international=True` and a locale with symbol following value. -E.g. `locale.currency(1345345345352.22, international=True)` returned `'1345345345352,22 EUR '` instead of `'1345345345352,22 EUR'` on Ubuntu. Windows 10 was not affected. \ No newline at end of file +E.g. `locale.currency(12.34, international=True)` returned `'12,34 EUR '` instead of `'12,34 EUR'`.