[New-bugs-announce] [issue35336] Bug in C locale coercion with PYTHONCOERCECLOCALE=1

STINNER Victor report at bugs.python.org
Wed Nov 28 05:42:16 EST 2018


New submission from STINNER Victor <vstinner at redhat.com>:

PYTHONCOERCECLOCALE=1 should not force C locale coercion, Python should still check if the LC_CTYPE locale is "C".

Bug:

$ ./python -c 'import locale; print(locale.setlocale(locale.LC_CTYPE, None))'
fr_FR.UTF-8
$ PYTHONCOERCECLOCALE=1 ./python -c 'import locale; print(locale.setlocale(locale.LC_CTYPE, None))'
C.UTF-8

It should be fr_FR.UTF-8 as well in the second example :-( It seems to be a regression that I introduced in the middle of my refactoring on the Python initialization.

The bug is around:

static void
config_init_locale(_PyCoreConfig *config)
{
    if (config->coerce_c_locale < 0) {
        /* The C locale enables the C locale coercion (PEP 538) */
        if (_Py_LegacyLocaleDetected()) {
            config->coerce_c_locale = 1;
        }
    }
    ...
}

The 3.7 branch and the 3.7.0 release are affected :-(

$ ./python -V
Python 3.7.0
$ PYTHONCOERCECLOCALE=1 ./python -c 'import locale; print(locale.setlocale(locale.LC_CTYPE, None))'
C.UTF-8

----------
components: Interpreter Core
messages: 330590
nosy: vstinner
priority: normal
severity: normal
status: open
title: Bug in C locale coercion with PYTHONCOERCECLOCALE=1
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35336>
_______________________________________


More information about the New-bugs-announce mailing list