This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author canuck7
Recipients canuck7
Date 2018-12-06.21:54:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1544133264.0.0.788709270274.issue35432@psf.upfronthosting.co.za>
In-reply-to
Content
The short story: Small numbers are not displayed properly when using a French (language) locale or similar, and formatting output with str.format or string.Formatter(). The problem probably extends to other locales.

Long story:

---
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'fr_CA.UTF-8'
>>> print('{:n}'.format(10))    # Garbled output

>>> print('{:n}'.format(10000)) # OK
10 000
>>> # Note: narrow non-break space used as thousands separator
... pass
>>> locale.format_string('%d', 10, grouping=True)      # OK
'10'
>>> locale.format_string('%d', 10123)                  # OK
'10123'
>>> locale.format_string('%d', 10123, grouping=True)   # OK thousands separator \u202f
'10\u202f123'
>>> import string
>>> print(string.Formatter().format('{:n}', 10))  # Same problem with Formatter
AB
>>> print(string.Formatter().format('{:n}', 10000))
10 000

locale aware functions implementing the {:n} formatting code, such as str.format and string.Formatter, generate garbled output with small numbers under a French locale.

However, locale.format_string('%d', numeric_value) produces valid strings. In other words, it's a workaround for the time being...

The problem seems to originate from a new version of Ubuntu: I ran the same program about 18 months ago and didn't notice any problem.

My 0.02 $ worth of analysis: the output from the str.locale function is some random and changing value with small numbers. The behavior is reminiscent of invalid memory reads in C functions, e.g., mismatch of  parameter in function calls, or similar. The value is not consistent. It feels like format does not expect and deal properly with long Unicode characters as part of numbers. The space character is a NARROW NON-BREAK SPACE, in most Ubuntu French locales (and quite a few others) however.

The problem shows up in Python 3.6 and 3.7.

This might also be a security issue...
History
Date User Action Args
2018-12-06 21:54:24canuck7setrecipients: + canuck7
2018-12-06 21:54:23canuck7setmessageid: <1544133264.0.0.788709270274.issue35432@psf.upfronthosting.co.za>
2018-12-06 21:54:23canuck7linkissue35432 messages
2018-12-06 21:54:23canuck7create