New submission from Martin Panter:

On a Linux computer I have LANG=en_US.utf8 set. Python 3 initializes the locale 
with this setting (see revision 43e32b2b4004):

>>> locale.setlocale(locale.LC_CTYPE)  # Get setting initialized by Python
'en_US.utf8'

In Lib/test/test___all__.py, there is a special case to restore the locale 
after loading the “readline” module (last changed in revision 37ed6eed0595). It 
does this by calling getlocale() and later setlocale(). However the getlocale() 
call translates the setting to UTF-8 in uppercase with a dash, and setlocale() 
keeps it that way:

>>> locale.getlocale(locale.LC_CTYPE)
('en_US', 'UTF-8')
>>> locale.setlocale(locale.LC_CTYPE, _)
'en_US.UTF-8'

This means that the test framework may complain:

Warning -- locale was modified by test___all__

One subtlety is that I only see the warning when the “tkinter” module is 
unavailable. Otherwise, the test imports Lib/idlelib/iomenu.py, which calls 
setlocale(locale.LC_CTYPE, "") and restores the original “utf8” spelling.

The easiest fix would be to use setlocale(locale.LC_CTYPE) instead of 
getlocale() in test___all__. However I think it may be safe to remove this code 
entirely. The original version of the it was added by Guido in revision 
ba522c74a931 (year 2002). Three hours later is revision c7d5801bbae8, where 
Guido changed the “readline” module to restore the locale after Readline 
library initialization. Since the module is fixed, I don’t think we need the 
test workaround, and I propose to remove it in Python 3, where it causes the 
above conflict.

----------
components: Tests
files: readline-getlocale.patch
keywords: patch
messages: 285467
nosy: martin.panter
priority: normal
severity: normal
stage: patch review
status: open
title: test___all__ alters utf8 locale setting
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file46287/readline-getlocale.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29273>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to