Conversation
…coding Text mode documents which encoding is used and not that the value is a guess about the child process, so a wrong guess reads as a bug in this module: the output is either silently mojibake, or a UnicodeDecodeError raised while the stream is read, reported from inside subprocess rather than from the call that is missing encoding=. The warning keeps to what was asked for on pythongh-105312: the default is a guess, pass encoding= on every platform, and on Windows more than one default is in force at once -- the ANSI code page and the console output code page -- so a console child is read with the console page while a Python child can be told what to write through PYTHONUTF8 / PYTHONIOENCODING.
Documentation build overview
|
Author
|
CLA signed — the check is green now, and so are Rendered warning, for review without a local build: https://cpython-previews--158634.org.readthedocs.build/en/158634/library/subprocess.html#frequently-used-arguments — the five cross-references in it ( Happy to trim it if it reads long for one admonition; the Windows paragraph is the part I would cut first, since the first one carries the advice on its own. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documentation only. Closes #158633, and implements what @zooba described on #105312:
One
.. warning::in frequently-used-arguments, after the paragraph on binary mode.Popen's section already refers to that one, so it is covered too.Two things the current text leaves out, and the reason they are worth a warning rather than a note:
Where the failure appears. When the guess is wrong the output is either silently mojibake, or a
UnicodeDecodeErrorraised while the stream is read — and that traceback comes from insidesubprocess, not from the call that omittedencoding=, which is what sends people looking for a bug in the module.Windows has more than one default at once. Measured on Windows 11, ANSI code page
cp1251, console output code pagecp866, so two children of one process need two different decoders:Under UTF-8 mode, which :pep:
686makes the default in 3.15, the second becomesUnicodeDecodeError: 'utf-8' codec can't decode byte 0x92rather than correct text — so the advice holds after 3.15, which is why the warning says so explicitly instead of presenting UTF-8 as the end of the problem.The Windows paragraph keeps to @zooba's caveat that
GetConsoleOutputCPis only right if you know the child uses it: it says a console program is read with that page, and that a Python child can instead be told what to write throughPYTHONUTF8/PYTHONIOENCODINGin itsenv, which is knowledge rather than a guess.No behaviour change and no new API, so I believe this is
skip news; happy to add a blurb if you would rather have one. I have not signed the CLA yet — doing that now, and I will confirm here once it shows.