◐ Shell
clean mode source ↗

bpo-28180: Fix the implementation of PEP 538 on Android by xdegaye · Pull Request #4334 · python/cpython

I was attempting to figure out how this differs from the existing logic in _Py_LegacyLocaleDetected, and it seems to me that this is requiring not only that the locale category LC_ALL be set to C.UTF-8 (which this code still forces unconditionally below), but also that either LANG or LC_CTYPE (or both) be set to C.UTF-8 in the environment.

If I've understood that correctly, then the only real effect of the call to _Py_CoerceLegacyLocale here that isn't already covered by the setlocale call below is to do setenv("LC_CTYPE", "C.UTF-8", 1), just in a roundabout way that doesn't make it clear that that's all it is going to do.

If that's right, then I'd suggest just putting an unconditional setenv("LC_ALL", "C.UTF-8", 1) here to align with the setlocale call, and amende the comment to say something like "While setlocale doesn't check the environment variables, some other ported code may (e.g. in extension modules), so we make sure that the env vars match the forced locale configuration"