WIP bpo-34589: Move locale coercion back to the CLI app#9257
Conversation
vstinner
left a comment
There was a problem hiding this comment.
I dislike the idea of having PYTHONCOERCECLOCALE env var which behaves differently than all other PYTHON* env vars. See my -X proposal: https://bugs.python.org/issue34589#msg325282
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
|
I merged my PR #9073 instead: it is closer to the current code, allows to implement a new -X coerce_c_locale command line option, and still respects -E and -I option: ignore PYTHONCOERCECLOCALE. Maybe we can refactor the Python initialization code later, but we need a fix on the current code before 3.7.1 release which is scheduled tomorrow by our release manager, Ned. |
Sorry, something went wrong.
|
What the hell Victor? This is NOT OK! |
Sorry, something went wrong.
Victor is attempting to arbitrarily overrule the PEP process
|
I've dismissed Victor's review, as he is inappropriately attempting to overrule the PEP process due to his personal preferences. |
Sorry, something went wrong.
|
@vstinner "Closer to the current code" is not an advantage when the structure of the current code goes completely against the way PEP 538 was designed to work (i.e. the CPython runtime never even seeing the original uncoerced locale, except in the locale coercion helper functions) |
Sorry, something went wrong.
…le-coercion-back-to-the-intended-location
|
Initial Travis failure affecting bb16468 was in test_nntplib relating to being unable to assign an address, so I restarted the job. |
Sorry, something went wrong.
|
Got the test_nntplib failure again, so restarted all the CI checks. See https://bugs.python.org/issue19756 (in particular, the last couple of comments) |
Sorry, something went wrong.
|
Moved back to WIP, as I plan to make further changes to the docs wording, and will be making it so that PYTHONCOERCECLOCALE is always handled the same way as the C-level locale configuration variables: read as ASCII independently of the Python |
Sorry, something went wrong.
…le-coercion-back-to-the-intended-location
- PYTHONCOERCECLOCALE is handled the same way as LANG, LC_CTYPE and LC_ALL (i.e. independently of -E and -I) - locale coercion tests are once again running in isolated mode - be explicit that the env var key and value must be encoded as ASCII to have any effect - implement bpo-30672, such that the POSIX locale is always handled the same way as the C locale, even when it isn't a simple platform level alias for the latter
9ff65d7 to
e48e5b7
Compare
September 30, 2018 07:19
|
@vstinner I know you object-in-principle to the idea of having The big items are:
(This isn't urgent, since it's currently only for Python 3.8, and even if a variant of it does get backported, it would be for 3.7.2 at the earliest) |
Sorry, something went wrong.
|
Sorry, I will not review this change. (If you want my opinion, I dislike the PR since it introduces an exception to the -E option and I dislike that.) |
Sorry, something went wrong.
|
Sorry this is taking so long. I wasn't super familiar with the locale stuff so I've been taking my time to make sure I've got it straight. Let me make sure I understand the change correctly. Status quo:
This PR:
Here are the differences I noticed: Status quo:
This PR:
In practice, it seems that the key changes are:
|
Sorry, something went wrong.
ericsnowcurrently
left a comment
There was a problem hiding this comment.
The change makes sense to me, especially in light of the following from PEP 538:
The interpreter will always check for the PYTHONCOERCECLOCALE environment variable at startup (even when running under the -E or -I switches), as the locale coercion check necessarily takes place before any command line argument processing. For consistency, the runtime check to determine whether or not to suppress the locale compatibility warning will be similarly independent of these settings.
There are a few minor things to address otherwise.
One point of clarification: is it intentional that the warning is not emitted under -E even if the locale is coerced?
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
…le-coercion-back-to-the-intended-location
…le-coercion-back-to-the-intended-location
…le-coercion-back-to-the-intended-location
|
While messing with the current locale setting from a support library rather than the main application still bothers me, I've come to the conclusion that it doesn't bother me enough to want to introduce a non-trivial distinction between the way Python 3.7 handles this scenario, and the way Python 3.8+ handles it. https://bugs.python.org/issue34589#msg332123 provides a bit more rationale (essentially, I expect that the the combination of circumstances required for there to be an externally observable difference in behaviour between Python 3.7.0 and this PR is going to be sufficiently rare that it simply isn't worth adding a net 200+ lines of code to maintain). Accordingly, closing this PR and the associated issue indefinitely - while I preferred the original simpler implementation of locale coercion in isolation, all the machinery that the current more complex implementation relies on has to exist to handle UTF-8 mode anyway, so reverting locale coercion back to its original implementation model would end up making the interpreter as a whole more complicated (both to maintain, and to understand). |
Sorry, something went wrong.
This PR moves locale coercion back to happening as soon as possible in the CLI app, so there's no re-encoding dance involved in handling it, and so you can emulate systems that don't have a suitable target locale with
PYTHONCOERCECLOCALE=0, even when working on code that runs with-Eor-I.To help with the documentation enhancements in the PR, it also implements [bpo-30672](https://www.bugs.python.org/issue30672) (which makes the POSIX locale behave the same way as it does on glibc, even when it's not a simple alias for the default C locale)
https://bugs.python.org/issue34589